[PATCH] Ash support for replace and subsitution

Lombard, David N dnlombar at ichips.intel.com
Tue Mar 25 15:50:16 UTC 2008


On Tue, Mar 25, 2008 at 01:25:56AM +0100, Denys Vlasenko wrote:
> On Monday 24 March 2008 18:14, Paul Smith wrote:
> > On Mon, 2008-03-24 at 16:51 +0000, James Simmons wrote:
> > > I have no problem with a NON_POSIX_EXTENSIONS. Is this true with the
> > > other patches I posted?
> > 
> > Well, maybe we should wait for a ruling by Denys or someone.  I'd really
> > love to have a POSIX-standard shell in busybox, and I had this idea that
> > that was a design goal of ash.
> > 
> > But I could be wrong.  For example, the extended test notation [[ ... ]]
> > is not POSIX, but (according to your patch; I haven't checked it myself)
> > it's already supported.
> 
> Stupid question alert.

Not a stupid question...

> What is the difference between "test"/"[" and "[["?

test and "[" behave the same.  Ignoring shell built-ins for the moment, "[" is
a link to /usr/bin/test (or the bb binary in our case).

"[[" on the other hand is *always* a built-in; more to the point, parameter
expansion and word splitting behave differently because of this.

To be clear

	$ unset a
	$ echo $a | od
	0000000 000012
	0000001
	$ [ $a = "" ] && echo mt
	bash: [: =: unary operator expected
	$ [ "$a" = "" ] && echo mt
	mt
	$ test $a = ""  && echo mt
	bash: test: =: unary operator expected
	$ test "$a" = ""  && echo mt
	mt
	$ [[ $a = "" ]] && echo mt
	mt
	$

As you see, the double-bracket version *does not* require quotes around
a null variable/result to execute correctly while the older version does,
as it is (or can be) passing a command line to another binary.

Beyond this very important distinction, the "[[" form has additional/better
operators, e.g.,

	[[ this && that || the_other ]]

-- 
David N. Lombard, Intel, Irvine, CA
I do not speak for Intel Corporation; all comments are strictly my own.



More information about the busybox mailing list