Bug 465

Summary: ash: "[ ! ]" no longer works
Product: Busybox Reporter: David <panadero_pizza>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.13.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target: i386-uclibc
Build:
Attachments: Fix

Description David 2009-07-16 09:35:19 UTC
I have recently upgraded from busybox 1.11.1 to 1.13.2 (latest/current stable in gentoo distro!).

After this I have noticed that the "if" statement (ash) doesn't understand any more the negation of empty variables:

if [ ! $variable_that_has_not_yet_been_defined ]; then

This will fail with the error message: "sh: argument expected", whereas in busybox 1.11.1 the command list after "then" would have been executed. As a consequence busybox 1.13.2 is now less portable (standard "bash" accepts the anterior line without complaints).

This behaviour is also not very coherent because empty variables are still accepted, if not negated:

if [ $variable_that_has_not_yet_been_defined ]; then
else
fi

"ash" will execute the else part of this code - without complaint on the error stream.

As the following lines should be executed in the same manner (and old busybox and likewise bash do so) without error message, I think this should be fixed.

if [ ! $variable_that_has_not_yet_been_defined ]; then
if ! [ $variable_that_has_not_yet_been_defined ]; then
if [ ! "$variable_that_has_not_yet_been_defined" ]; then
if ! [ "$variable_that_has_not_yet_been_defined" ]; then

(with and without negation this should work equally!)
Comment 1 Mike Frysinger 2009-07-16 17:50:36 UTC
the surrounding aspects are noise here.  the only thing that matters is this:
[ ! ]

that statement should work in every shell, but it seems to be broken atm in ash
Comment 2 Denys Vlasenko 2009-07-16 22:34:01 UTC
Created attachment 477 [details]
Fix

Please try attached patch