[ means test right? Maybe? (was: Re: GOTCHA in Ubuntu - broken shell)
Tom Buskey
tom at buskey.name
Mon Oct 1 11:19:44 EDT 2007
On 10/1/07, Flaherty, Patrick <pflaherty at wsi.com> wrote:
>
> > =>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?
It sounds like dash is breaking lots of people's assumptions.
I do a man test on Fedora 7 and it does not show ==. On Solaris 10, it has
an example of == for csh.
Man bash & ksh on Fedora 7 shows == for both. bash on Solaris shows == for
bash, but nothing for ksh.
And of course, [ is a builtin whereas test is /bin/test. Linux has
/usr/bin/[ so you could be explicit, but most shells substitute their
builtin [.
Here's the relevant bash (3.2.9) man page on Fedora 7:
string == pattern
True, if string matches pattern. Any part of pattern can
be
quoted to cause it to be matched as a string. With a
successful
match to a pattern, the .sh.match array variable will
contain
the match and sub-pattern matches.
string = pattern
Same as == above, but is obsolete.
And Solaris (bash 3.00.16):
string1 == string2
True if the strings are equal. = may be used in place
of == for strict POSIX compliance.
Sounds like dash isn't fully cooked. == is used & works in ksh, bash and
sh.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20071001/4a2aab99/attachment.html
More information about the gnhlug-discuss
mailing list