How to find if folder name contains spaces in Bash

159 Views Asked by At

I have text file (file.txt) containen folders:

/Volumes/my driver/foo/
/Volumes/drive 2/bar/
...

Then I want to find like jpg files and open in app. The problem is that find doesn't accept space if are in list even I add quotes to the text file. like

cat file.txt | while read -r line ; do
    result=$(find $line -name '*.jpg')
done

Then next problem would be to read result to table and open it in app.

1

There are 1 best solutions below

3
anubhava On

The problem is that find doesn't accept space

That's not correct. You just need to make sure to remove unnecessary cat, use loop properly and quote variable properly like this:

while IFS= read -r line ; do
    result=$(find "$line" -name '*.jpg')
    echo "do something with $result"
done < file.txt