bug-bash
[Top][All Lists]
Advanced

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

Re: problem with test cmd


From: Chet Ramey
Subject: Re: problem with test cmd
Date: Wed, 14 Feb 2001 08:14:59 -0500

> Probably this is not new for you, but certainly it is for me. Please take a 
> look at the following:
> 
> bash$ MYVAR=rr
> bash$ [ -n $MYVAR ]
> bash$ echo $?
> 0
> bash$ MYVAR=
> bash$ [ -n $MYVAR ]
> bash$ echo $?
> 0
> bash$ unset MYVAR
> bash$ [ -n $MYVAR ]
> bash$ echo $?
> 0
> bash$
> 
> So in the first case test returns zero, which is correct for the current 
> value of MYVAR, but in the second and third cases it remains returning zero, 
> which seems wrong to me. I also tested with -z, which seems to be working 
> right in all cases. BTW, [ -n '' ] (i.e. literal string, no expansion) works 
> correctly too.

Bash is behaving properly.  In the second case, the unquoted $MYVAR expands
to nothing, which leaves [ -n ], which is true.  Look at the Bash FAQ,
question E1, for more information.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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