Hi Stefano,

On 22 Nov 2011, at 03:13, Stefano Lattarini wrote:
> Hi Gary.  Few more random nits...

Thanks ;)

> On Monday 21 November 2011, Gary V wrote:
>> To safely use a non-literal first argument to `test', you must
>> always prepend a literal non-`-' character, but often the second
>> operand is a constant that doesn't begin with a `-' already, so
>> always use `test a = "$b"' instead of noisy `test "X$b" = Xa'.
>> 
> This seems "back-bending" to me, and slightly unclear to read.  Also,
> it goes against the (unofficial) conventions of autoconf, which is
> to use either `test "x$b" = xa' or `test "x$b" = Xa'.

I was unable to find any shells that choke on:

  test a != -b || echo bug

Where it's easy to upset test with:

  test -b != a

> Also ...
> 
>> # Bootstrap this package from checked-out sources.
>> # Written by Gary V. Vaughan, 2010
>> @@ -1760,7 +1760,7 @@ func_ifcontains ()
>>       ;;
>>     esac
>> 
>> -    test "$_G_status" -eq 0 || exit $_G_status
>> +    test 0 -eq $_G_status || exit $_G_status
>> }
> ... changes like this seems overly paranoid, in case $_G_status is
> expected (as I surmise it is) to be a non-negative integer.  And
> if this assumption stps to hold dur to a bug in your code, you are
> going to be bitten by much worse problem anyway:

Well, in addition to saving a few characters of typing, and being
consistent with other uses of test after this patch, it also prevents
the syntax-check from triggering.

I certainly wouldn't expect any difference in behaviour either way,
even on buggy shells/test implementations.

> # $shell is either Solaris 1 0or AT&T ksh, Solaris 10 XPG4 sh, or
> # zsh 4.3.12.
> $ $shell -c 'exit t; echo foo'; echo status = $?
> status = 0

Cheers,
-- 
Gary V. Vaughan (gary AT gnu DOT org)

Reply via email to