Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read filenames from a text file and then make those files?

Tags:

linux

bash

unix

My code is given below. Echo works fine. But, the moment I redirect output of echo to touch, I get an error "no such file or directory". Why ? How do i fix it ? If I copy paste the output of only echo, then the file is created, but not with touch.

while read line           
do           
    #touch < echo -e "$correctFilePathAndName"
    echo -e "$correctFilePathAndName"           
done < $file.txt
like image 773
Steam Avatar asked Dec 29 '25 17:12

Steam


1 Answers

If you have file names in each line of your input file file.txt then you don't need to do any loop. You can just do:

touch $(<file.txt)

to create all the files in one single touch command.

like image 142
anubhava Avatar answered Jan 01 '26 10:01

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!