//View Tip #67
Similar Tips
» list the most recent files in a directory
» Zero files
» Local/remote webserver
» ssh proxy forwarding
» User input timeout

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Loop over files with spaces in the name:

(Wrong) example:
$ touch a

$ touch b\ c
$ for i in *; do ls $i; done;
a
ls: b: No such file or directory
ls: c: No such file or directory


The trick is to change the separator ($IFS) to newline:
old_ifs=$IFS

IFS="
"
$ for i in *; do ls $i; done;
a
b c


View Comments »




Comments 

Add your comment

Comments are currently disabled
thanks for the '$IFS' trick...
following method works too:

$ touch a
$ touch b\ c
$ for i in *; do ls "$i"; done;
Posted 2008-10-25 18:59:36

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit