choice of control operators in scripts

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Tue May 13 12:28:18 UTC 2008


On Tue, 13 May 2008, Bernhard Fischer wrote:

> And of course i've seen those dreaded test(1) impls that
> misinterpret arbitrary strings as args (hence "x$myvariable" != "x")
> and some ancient test(1) impls don't support -n and/or -z, fwiw.

Alright.  I think it's ok using the x-thing in tests.  I have
no problems with using that.  Question is what makes this:

  [ "x$myvariable" != "x" ]

or this:

  [ x"$foo" != x"" ]

or this:

  [ x"$foo" != x"bar" ]

safer than this:

  [ x$foo != x ]

or this:

  [ x$foo != xbar ]

Do '$foo', 'bar' or the empty string need to be quote protected?

> Either we add some basic sanity-test as 0000.tests

Good idea.


Cheers,

-- 
Cristian



More information about the busybox mailing list