Problem with ash -n non-zero length string test

Dallas Clement dallas.a.clement at gmail.com
Sun Jul 15 21:46:28 UTC 2007


> -----Original Message-----
> From: Denis Vlasenko [mailto:vda.linux at googlemail.com]
> Sent: Saturday, July 14, 2007 8:02 PM
> To: busybox at busybox.net; dallas.a.clement at gmail.com
> Subject: Re: Problem with ash -n non-zero length string test
> 
> On Saturday 07 July 2007 22:34, Dallas Clement wrote:
> > Hello All,
> >
> > I'm experiencing some weird things when trying to use -n to test for
> a
> > non-empty string as in the following example.
> >
> > boot_drive_name=""
> >
> > if [ -n $boot_drive_name ]; then
> >    retval=0
> > else
> >    echo "Could not determine boot drive name."
> > fi
> >
> > To my surprise, this condition evaluates true and I do not see my
> echo
> > message.
> 
> No bug here:
> 
> # cat zz.sh
> boot_drive_name=""
> if [ -n $boot_drive_name ]; then
>  retval=0
> else
>  echo "Could not determine boot drive name."
> fi
> # ash zz.sh
> # bash zz.sh
> 
> It's error in script. You need to use
> 
> if [ -n "$boot_drive_name" ]; then...
> --
> vda

Thank you for your reply.  I didn't know that variables must be
double-quoted.  I'm learning something everyday! :>)




More information about the busybox mailing list