Hi Eric, On 22 Nov 2011, at 03:07, Eric Blake wrote:
> On 11/21/2011 07:47 AM, Gary V. Vaughan 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'. > > Not true. > > test a = "$b" > > is just as likely to trigger improper evaluation in buggy test(1) > implementations as: > > test "$b" = a :-o For real? On non-museum pieces? I tested a bunch of /bin/sh, bash, ksh and zsh versions that I have easy access to, and for all of them, the only way to upset test with leading hyphens is in the first argument. > If you cannot guarantee the contents of "$b", then you MUST prefix both > sides of the comparison with x or X. Conversely, if you CAN guarantee > the contents of "$b" (for example, if you did b=$?, then you KNOW that b > is a numeric tring with no problematic characters), then you might as > well use the more idiomatic comparison of variable to constant. I don't suppose you can point me at a shell that chokes or fails on: test a != -b || echo bug ? Or at least some reliable documentation that shows we're not dealing with outdated dogma here? I'll postpone pushing this patch until we get to the bottom of the issue though. Cheers, -- Gary V. Vaughan (gary AT gnu DOT org)