Fun w/ test :)
Denys Vlasenko
vda.linux at googlemail.com
Mon Jul 21 22:46:28 UTC 2008
Paul, hi. :)
On Monday 21 July 2008 20:35, Chris Larson wrote:
> clarson at foul busybox% ./busybox test -f =
> clarson at foul busybox% ./busybox test \( -f = \)
> test: closing paren expected
>
> Hehe. I highly doubt anyone would actually name a file =, but what the heck, figured you'd
> want to know about any cases that confuse the parser. It's interesting to note that -f =
> works, but ( -f = ) does not. No customer issue on this of course, just made myself try
> lots of combinations during the testing.
>
> I found a case where the "unknown operand" error is seen. If it sees an operand after an
> expression, which is not -o or -a, it gives that error:
> clarson at foul busybox% ./busybox test -f = -a
> clarson at foul busybox% ./busybox test -f = -a -e foo
> test: -e: unknown operand
>
> Due to the precedence, that's seen as two expressions without a -a or -o to join them.
> The error message could be confusing in this case. -e is, of course, a valid
> operator, and -e foo is a valid expression, but -e is not valid -there-, only
> -a or -o are.
So, now, do you see why x"str" trick is actually not so silly?
On Thursday 15 May 2008 02:20, Paul Fox wrote:
> > You're talking again of som general case. In this particular case:
> >
> > [ x"$foo" != x ]
> >
> > it's totally useless quoting an empty string after the 'x' on the
> > right side of the condition.
>
>
> sigh. why would you write this at all? either say what you
> mean, and write:
> [ "$foo" != "" ]
>
> or say it in the usual shell idiom and write:
> [ "$foo" ]
> or
> [ -n "$foo" ]
>
> but this
> [ x"$foo" != x ]
> or this
> [ x"$foo" != x"" ]
>
> are just silly.
>
> paul
> =---------------------
> paul fox, pgf at brightstareng.com
--
vda
More information about the busybox
mailing list