[oe] Use of == in shell scripts

Mike Detwiler j.michael.detwiler at gmail.com
Wed Oct 27 01:47:00 UTC 2010


On Tue, Oct 26, 2010 at 7:36 PM, Andreas Oberritter
<obi at opendreambox.org> wrote:
> On 10/26/2010 06:29 PM, Michael Smith wrote:
>> Andreas Oberritter wrote:
>>> On 10/26/2010 05:31 PM, Andreas Oberritter wrote:
>>>> How about splitting it into 5 patches?
>>>>
>>>> - classes (7 files)
>>>> - contrib (4 files)
>>>> - recipes/*/*.bb (24 files)
>>>> - recipes/*/*.inc (14 files)
>>>> - other files in recipes except recipes/obsolete (11 files)
>>>
>>> Or how about those 37 patches?
>>>
>>> http://git.opendreambox.org/?p=obi/openembedded.git;a=shortlog;h=refs/heads/equality-operator
>>>
>>>
>>> Rationale:
>>> - bbclasses: 1 patch per file
>>> - contrib and recipes: 1 patch per directory
>>
>> For the series:
>>
>> Acked-By: Michael Smith <msmith at cbnco.com>
>>
>> Except this one:
>>
>> http://git.opendreambox.org/?p=obi/openembedded.git;a=commitdiff;h=ad7b2c9ab0c305034c39d2efc5a52789965bb5c2
>>
>>
>> where some lines had == twice, looks like your sed may not have caught it.
>
> Thanks for spotting! I've updated the patch series and added your ack.
>
>> BTW, some of the files have constructs like this:
>>
>> if [ "x$HAS_MADWIFI" = "x1" ]
>>
>> I think this "x" business is for old broken shells that can't handle an
>> empty quoted string as the first argument. Does anyone know the standard
>> well enough to say? I figure [ "" = "1" ] should be legal everywhere.
>> This is just a pet peeve/bike shed on my part.
>
> Autotools use constructs like that everywhere, so it's likely increasing
> portability while decreasing readability.
>
> A random forum post suggests that some versions of '[' have problems, if
> the first operand equals '!' or '(' [1].

And the less random Autoconf manual has this to say about the shell
builtin, test, and it's more common name '[':

"Similarly, Posix says that both ‘test "string1" = "string2"’ and
‘test "string1" != "string2"’ work for any pairs of strings, but in
practice this is not true for troublesome strings that look like
operators or parentheses, or that begin with ‘-’.

It is best to protect such strings with a leading ‘X’, e.g., ‘test
"Xstring" != X’ rather than ‘test -n "string"’ or ‘test !
"string"’."[2]

See the discussion of 'test(string)' at the link below.

[2] http://www.gnu.org/software/autoconf/manual/autoconf.html#Limitations-of-Builtins

>
> It's not easy to search for [ or test or x on google. ;-)
>
> Regards,
> Andreas
>
> [1]
> http://www.techtalkz.com/unix/78138-testing-equality-bash-scripts.html#post329122




More information about the Openembedded-devel mailing list