For loops, Spaces in values

Daryl Tester Daryl.Tester at iocane.com.au
Tue Nov 28 09:33:35 CST 2006


Cameron Simpson wrote:

> Generally, this:
> 
>   for file in `listdirs`
>   do
>     ...
> 
> is better written:
> 
>   listdirs \
>   | while read -r file
>     do
>       ...

Or <http://www.linuxsa.org.au/pipermail/linuxsa/2006-May/083664.html>
which (un)sets IFS for the read command only.

> Of course, if you're really unlucky there can be newlines in the
> filenames too:-)

In which case use GNU find and its null terminating string option
(-print0 and xargs matching -0 option).

-- 
Regards,
  Daryl Tester, IOCANE Pty. Ltd.


More information about the linuxsa mailing list