[ means test right? Maybe? (was: Re: GOTCHA in Ubuntu - broken shell)

Flaherty, Patrick pflaherty at wsi.com
Mon Oct 1 11:00:42 EDT 2007


> =>Another example. This one is [was] my "favorite"; I think it was
> =>the first one to bork on me. The error message was [is] so obscure
> =>that for the past year I've lived with band-aiding each "if"
> =>statement one at a time, just to have something which works.
> =>(One uses "if" statements much more frequently than slicing.)
> =>In bash:
> =>  $ if [ "${breakfast}" == "spamandeggs" ]; then
> =>  >   echo "yummy"
> =>  > fi
> =>  yummy
> =>  $
> =>In dash:
> =>  $ if [ "${breakfast}" == "spamandeggs" ]; then
> =>  >   echo "yummy"
> =>  > fi
> =>  [: 11: ==: unexpected operator
> =>  $
> =>
> =>How ugly and unhelpful is that?
> =>
> =>The band-aid, by the way, was that "=" instead of "==" works.
> =>(And how ugly is THAT? And how do you explain that to a student?)
> 
> FYI, the correct operator is = and == is an extension of bash. ==
should
> not be used.
> 

I thought everything in those brackets was just an argument to test. The
= or == shouldn't be dependant on your shell, but on your coreutils
version. 

However, I tested it.
pack at dco-pflahertylx:~/hack$ cat test.dash 
#!/bin/dash

t="X"

if [ "$t" == "X" ]; then
 echo $t;
else
 echo "Not X"
fi
pack at dco-pflahertylx:~/hack$ dash test.dash 
[: 9: ==: unexpected operator
Not X
pack at dco-pflahertylx:~/hack$ bash test.dash 
X

...and now my world is turned upside down.

Anyone know why this works that way?



More information about the gnhlug-discuss mailing list