Fun w/ test :)

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Tue Jul 22 21:10:55 UTC 2008


On Tue, 22 Jul 2008, Denys Vlasenko wrote:

> I thought we are debationg usefulness of adding x prefix
> so that test (or [) does not get confused operators and strings.

Alright.  I might have missed something.

> This thread is a real-world example how people were bitten
> by this, and it contains an example: "test -f = -a -e foo"
> which actually fails on all three test implementations
> (busybox, bash, coreutils).

And dash:

  $ dash -c 'test -f = -a -e foo || echo failed'
  test: 1: -a: unexpected operator
  failed

> In this case x trick is not applicable, you need
> similar "./ trick" to guard filename from being
> mis-interpreted.
>
> test -f ./= -a -e foo

Yes.  That's one way to do it.  Another:

  $ ash -c 'test -f = && test -e foo || echo failed'
  failed

or:

  $ ash -c '[ -f = ] && [ -e foo ] || echo failed'
  failed


Cheers,

-- 
Cristian



More information about the busybox mailing list