[lug] bash scripting question

David L. Anselmi anselmi at anselmi.us
Sun Nov 20 11:36:55 MST 2005


Tkil wrote:
>>>>>>"Hugh" == Hugh Brown <hugh at math.byu.edu> writes:
> 
> 
> Hugh> for i in *;do command "$i"; done
> 
> Interesting that this is actually more robust than the "read" version.

Except when * expands to a list that is too long for the command line. 
That's currently a bigger problem for me than spaces or newlines in file 
names (though I bet I could drive some coworkers crazy putting a newline 
in a file).

<trivia>Do you know what characters aren't allowed in Unix file names? 
There are only two.</trivia>

[...]
> | $ ls -1 | while read file ; do echo "<$file>" ; done

ls always uses -1 when writing to something that isn't a tty.  You don't 
need to put it in explicitly.

Dave



More information about the LUG mailing list