Imagine a file list, list.txt, like this one

Naturally you could deal with it like so

Or just use the $i variable as its already the file and do a one liner like this:

cat list.txt | while read i; do dosomething "$i"; done This will dosomething against image1.jpg, image2.jpg and image3.jpg.

Easy simple loop.
Now imagine a file list with special characters like this one, listB.txt:

The same loops will not work and will error out. So you have to treat them like so:

Note: do not put quotes around the eval.

This will then properly process the files as it will naturally escape them.
It will properly run dosomething against those 5 files.

How does it do that? You can print out the FILE variable to understand. It simply backslashes (escapes) all of the special characters.

Output:

Sidenote: from talking with others, nohup dosomething &> whatever &  can be weird if dosomething has to operate on file with special characters. Instead its better to put it in the background and then just disown it, like so:

 

The end.

Leave a Reply

Your email address will not be published. Required fields are marked *