//View Tip #67
Similar Tips
» swap files
» Quit bash without saving history
» Bash
» Alter autocompletion settings
» Find and Grep

 

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