[PATCH] Ash support for replace and subsitution

Denys Vlasenko vda.linux at googlemail.com
Wed Mar 26 02:02:01 PDT 2008


On Tuesday 25 March 2008 22:16, James Simmons wrote:
> Okay. The below script shows the issue. It fails for busybox.
> 
> #!bin/sh
> 
> a=24
> b=47
> 
> if [[ "$a" -eq 24 && "$b" -eq 47 ]]
> then
> 	echo "Test succeeds"
> else
> 	echo "test fails"
> fi
> 
> If you apply this patch it works. Basically ash assumes everything in 
> between [[ and ]] is a TWORD instead of a conditional. If it does see the 
> && in between [[ and  ]] ash interpites it as a [[ ]] && instead. It does 
> a internal translation of && to -a and || to -o.

It is already applied in current svn. I believe I replied
to your first mail with this patch. Thanks, good job!

Remaining issues with [[ ]]:

ash does not "auto-quote" to prevent word splitting:

# ./busybox ash -c 'v="a b"; [[ $v = "a b" ]]; echo $?'
ash: b: unknown operand
2
# bash -c 'v="a b"; [[ $v = "a b" ]]; echo $?'
0

ash does not do "conditional operators such as -f
must be unquoted to be recognized as primaries" part:

# ./busybox ash -c '[[ "-e" /tmp ]]; echo $?'
0
# bash -c '[[ "-e" /tmp ]]; echo $?'
bash: -c: line 0: conditional binary operator expected
bash: -c: line 0: syntax error near `/tmp'
bash: -c: line 0: `[[ "-e" /tmp ]]; echo $?'

--
vda


More information about the busybox mailing list