[arch-general] BASH no longer does 'for i in $(ls); do ls $i; done'??

David C. Rankin drankinatty at suddenlinkmail.com
Wed May 19 03:22:29 EDT 2010


On 05/19/2010 01:48 AM, Jan de Groot wrote:
> On Wed, 2010-05-19 at 01:41 -0500, David C. Rankin wrote:
>> So the bottom line is don't alias 'ls'. And, I guess, the next
>> question would
>> be, how or where can I safely customize the behavior of ls without
>> screwing
>> myself again. 
> 
> Solution is simple: don't use ls for the for loops you're doing. I just
> tested it on my system, the colored files and directories give "No such
> file or directory", which makes sense, as the variable contains ascii
> chars for color information.
> 
> I would suggest using globbing, why would you use for i in $(ls); while
> you can use for i in *;
> 
> 

Jan,

	Point well taken. I don't know how I fell into that trap. Globbing is the way
to go. I guess it was just more logical to do for i in (the list); and when
thinking about "What gives me 'the list'", the ls trap found another victim :p

-- 
David C. Rankin, J.D.,P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com


More information about the arch-general mailing list