bug-bash
[Top][All Lists]
Advanced

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

Re: ls doesn't work in if statements in bash 4.3


From: Mike Frysinger
Subject: Re: ls doesn't work in if statements in bash 4.3
Date: Wed, 26 Mar 2014 21:15:22 -0400
User-agent: KMail/4.12.3 (Linux/3.13.0; KDE/4.12.3; x86_64; ; )

On Wed 26 Mar 2014 17:45:33 billycongo@gmail.com wrote:
> I thought about the changes I have made recently and I had added the
> following into my .bashrc:
> 
> eval $(dircolors -b ~/.dir_colors)
> 
> I commented it out, and now everything works.  I think it's still a bug,
> though I know how to fix it.

doubtful the problem is bash.  if ls is writing control codes, then bash will 
treat them as part of the filename.  you can verify by piping the output 
through hexdump and seeing what shows up.

this is a good example though of why using `ls` is almost always the wrong 
answer.  use unadorned globs:
        for f in dog*; do ...

i'd point out that if any of the files in your dir have whitespace, your code 
would also break:
        touch 'dog a b c'
        for f in `ls dog*`; do ...
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]