Bug 845

Summary: ASH fails to handle semi-complex "test"
Product: Busybox Reporter: Myke Smith <mykesmith1>
Component: OtherAssignee: unassigned
Status: RESOLVED WORKSFORME    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Host: Target:
Build:

Description Myke Smith 2010-01-07 18:08:41 UTC
Encountered this problem in running Oprofile's control script (opcontrol) on BusyBox 1.11.2.

This shows up when you use the single character option, for instance  "-d" instead of the "--dump" option. The problem occurs when you do

if test -z "$2" -a "$1" = "--reset";  then

running with -xv option I see using the "-d" option

+ test -z  -a -d = --reset                        <<<<<<<<<< $2  evaluates to null, $1 evaluates to -d
sh: --reset: unknown operand          
+ load_module

running with -xv option I see using the "--dump" option

+ test -z  -a --dump = --reset                <<<<<<<<<< $2 evaluates  to null, $1 evaluates to --dump
+ load_module

I tried as an alternative

if [  \( -z "$2"\) -a \("$1" = "--reset" \) ]; then

but using either the -d or --dump option I got
+ [ ( -z ) -a (-d = --reset) ]
sh: closing paren expected      

The only workaround that works is:

 if test \( -z "$2"\) -a \("$1" = "--reset" \) ; then

+ test ( -z ) -a (-d = --reset )                 <<<<<<<<<< $2  evaluates to null, $1 evaluates to -d
+ load_module

+ test ( -z ) -a (--dump = --reset )      <<<<<<<<<< $2  evaluates to null, $1 evaluates to --dump
+ load_module
Comment 1 Denys Vlasenko 2010-01-08 12:14:33 UTC
This was fixed in later versions. 1.11.2 is old.
Comment 2 Myke Smith 2010-01-30 23:22:16 UTC
Unable to move up to a newer version of BusyBox so I am not able to personally check. I will leave the resolution as is.

Do you me to move this to CLOSED?
Comment 3 Denys Vlasenko 2010-02-01 02:58:35 UTC
CLOSED or RESOLVED, I don't see the difference