[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Unix-ify File Names



H.S. <hs.samix@gmail.com>:
> Frank Terbeck wrote:
>
>> b) it breaks on filenames with spaces (and other special characters).
>>     While newlines and other special characters might be rather weird
>>     for filenames, spaces are perfectly okay and normal in filenames.
>>     Using 'for i in `ls *`'-type loops breaks this and is one of the
>>     main reasons why people think spaces are bad in filenames.
>>     (They are not bad, some people just do not know how to handle
>>     them properly.)
>
> I usually get by this problem by enclosing the variable in double quotes 
> within the for loop. A basic example:
>
> $> for f in *.jpg; do ls "$f"; done

Yeah, you are using the for-loop construct absolutely right.
I was arguing about

  for i in `ls *.jpg` ; do whatever "$i" ; done

And you are, of course, right, that in POSIX shells, parameters should
be double-quoted when used in almost every case, unless you know that
you want splitting by $IFS.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



Reply to: