[[ -z ]] nullglob problem?

2007-10-25 Thread Linus Swälas

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'  
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'  
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'  
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -O2  
-march=pentium-m -mmmx -msse -pipe
uname output: Linux miranda 2.6.23 #3 PREEMPT Wed Oct 17 21:07:21 CEST  
2007 i686 i686 i386 GNU/Linux

Machine Type: i686-pc-linux-gnu

Bash Version: 3.1
Patch Level: 0
Release Status: release

Description:
[[ -z seem to handle nullglob variables incorrect.
See the Repeat-By below.

Repeat-By:

mkdir empty
shopt -s nullglob
if [[ -z empty/* ]]
then
echo empty
fi

Shouldn't this echo empty?

echo empty/* echoes nothing, as it should since nullglob is set.
However, the test if [[ -z empty/* ]] evaluates to false, not
true as it should. Or shouldn't it?

This works with [ anyway:

if [ -z empty/* ]
then
echo empty
fi

echoes empty.

Fix:
Use [ instead of [[.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/




Re: [[ -z ]] nullglob problem?

2007-10-25 Thread Chet Ramey
> Machine Type: i686-pc-linux-gnu
> 
> Bash Version: 3.1
> Patch Level: 0
> Release Status: release
> 
> Description:
> [[ -z seem to handle nullglob variables incorrect.
> See the Repeat-By below.
> 
> Repeat-By:
> 
> mkdir empty
> shopt -s nullglob
> if [[ -z empty/* ]]
> then
>   echo empty
> fi
> 
> Shouldn't this echo empty?

No, since, as documented, the conditional operator does not perform
pathname expansion on its operands.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
Live Strong.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://tiswww.tis.case.edu/~chet/