[PATCH] Ash support for replace and subsitution

Paul Smith paul at mad-scientist.us
Mon Mar 24 21:23:14 PDT 2008


On Tue, 2008-03-25 at 01:25 +0100, Denys Vlasenko wrote:
> What is the difference between "test"/"[" and "[["?

I mentioned this in an earlier email, but in case it got lost: [[ is
guaranteed to be a shell builtin and as such, it has some semantics
which make it a bit easier to use than test/[, which might be (and must
always behave as if it is) a separate program.

In particular, the expansion rules are modified so that you don't have
to worry about odd characters, variables expanding to empty strings,
etc... those odd quirks of test/[ that require simple workarounds like
quoting all variables.  Mostly, in [[ .. ]] the content is not word
expanded by the shell before the expression is evaluated.  Obviously
this cannot be true of test/[.

For some examples (from bash):

   $ foo=
   $ [ $foo = bar ]
   bash: [: =: unary operator expected

   $ [[ $foo = bar ]]
   # Works

Also, more obscure things like:

   $ foo='0 -eq'
   $ [ $foo ]
   bash: [: 0: unary operator expected

   $ [[ $foo ]]
   # Works

etc.  You get the idea.


More information about the busybox mailing list