It seems that the single-equals is POSIX, while the double-equals is a
bash extension that at one point bash preferred and extended the match
behavior of.

But, the bash manpage now documents double-equals  (when in the
context of the builtin test or its '[' alias) as equivalent to
single-equals.

The manpage notes that when using test (rather than '['), one should
always use single-equals, due to POSIX compatibility issues, in case
the script gets run by a shell without a builtin test.

Bash has another extended test, '[[', which does significantly
different, and expanded, things, but its behavior was inconsistent
across bash versions the last time it was relevant to my work.

Apparently bash's interpretation of single-equals isn't always exactly
POSIX-standard, depending on which bash settings are in effect. A
quick skim shows that it may or may not be case-insensitive, may or
may not be glob-active (older version), *is* glob-active (newer
versions, with caveats?)...

dash's behavior isn't saying "unknown operator '['". It's saying
"builtin-test-via-left-square-bracket: unknown operator '=='". I think
it's just phrasing it really poorly due to overly simplistic
backtracking in its parser (most recent symbol being assumed to be the
cause of the error, thus printed).



On 2/5/18, Ryan Prichard <rprich...@google.com> wrote:
> FWIW: I think the problem is the double-equals operator:
>
> $ /bin/dash -c 'if [ x = x ]; then echo foo; fi'
> foo
>
> $ /bin/dash -c 'if [ x == x ]; then echo foo; fi'
> /bin/dash: 1: [: x: unexpected operator
>
> $ /bin/dash -c 'if /usr/bin/[ x == x ]; then echo foo; fi'
> foo
>
> POSIX hasn't specified ==. I'm guessing it's strictly equivalent to =?
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
>
> -Ryan
>
>
> On Sun, Feb 4, 2018 at 6:11 PM, Rob Landley <r...@landley.net> wrote:
>
>> I tried adding this to configure:
>>
>> if [ "$(basename "$0")" == configure ]
>> then
>>   echo "This file is just a persistent place to set environment
>> variables."
>>   echo "You probably want to run 'make defconfig'."
>>   echo "Type 'make help' for more options, or see the README."
>>   exit 1
>> fi
>>
>> But if your #!/bin/sh points to the Defective Annoying SHell it
>> goes "unexpected operator [" EVEN THOUGH "[" IS IN THE $PATH,
>> and I'm just not going there.
>>
>> So I've put #!/bin/bash at the top, set the executable bit, and
>> I'm keeping the complaint to one line and running "make defconfig"
>> anyway on the theory making it easier to use is better than trying
>> to educating people with a pop-up window error.
>>
>> Rob
>> _______________________________________________
>> Toybox mailing list
>> Toybox@lists.landley.net
>> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>>
>
_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to