choice of control operators in scripts

Denys Vlasenko vda.linux at googlemail.com
Mon May 12 14:43:35 UTC 2008


On Monday 12 May 2008 14:29, Paul Smith wrote:
> On Sun, 2008-05-11 at 19:28 +0200, Cristian Ionescu-Idbohrn wrote:
> >    NAME="$1"
> > -  [ -z "$1" ] && NAME="$2"
> > +  [ -n "$1" ] || NAME="$2"
> 
> You can replace both these lines with:
> 
>   NAME="${1:-$2}"

This will make me to go read "man bash". Not that I remember
what -n and -z mean... I strongly prefer obvious:

[ "$foo" = "bar" ]

If you fell paranoid today (highly recommended),
add x"" to guard against less than ideal implementations of []
which can be confused by e.g. foo=-n :

[ x"$foo" = x"bar" ]

--
vda



More information about the busybox mailing list