bug-coreutils
[Top][All Lists]
Advanced

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

the `--color' option of `ls' shadows the shortcut evaluation scheme of `


From: Day
Subject: the `--color' option of `ls' shadows the shortcut evaluation scheme of `&&' and `||'
Date: Tue, 12 Feb 2008 11:35:08 +0800 (CST)

I found this bug when I tried a tiny script which checks a directory is empty 
or not.

 [ "$(ls -A ./dir)" ] && echo "Not Empty" || echo "Empty"

After `mkdir ./dir' and without adding anything into ./dir, run the script, the 
echoed message is "Empty". But when adding the `--color' option to `ls',


 [ "$(ls -A --color ./dir)" ] && echo "Not Empty" || echo "Empty"
 
the echoed message is always "Not Empty", regardless of the fact that ./dir is 
actually EMPTY. Below is the tested result.


day[~]$ mkdir dir
day[~]$ ls -l dir
total 0

day[~]$ [ "$(ls -A ./dir)" ] && echo "Not Empty" || echo "Empty"
Empty
day[~]$ [ "$(ls -A -F --color ./dir)" ] && echo "Not Empty" || echo "Empty"
Not Empty
day[~]$ [ "$(ls -A -F ./dir)" ] && echo "Not Empty" || echo "Empty"
Empty
day[~]$ [ "$(ls -A --color ./dir)" ] && echo "Not Empty" || echo "Empty"
Not Empty

Version Info:
ls (GNU coreutils) 6.9
GNU bash, version 3.1.17(2)-release

Linux zenwalk 2.6.23.12 #1 SMP PREEMPT Wed Dec 19 14:34:44 CET 2007 i686 AMD 
Turion(tm) 64 X2 AuthenticAMD GNU/Linux

PS: I have also tested on Ubuntu 7.10, the same result. So I think it's a 
common bug. 



--

DAY's
dAi Yi



reply via email to

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