Bug 465 - ash: "[ ! ]" no longer works
Summary: ash: "[ ! ]" no longer works
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.13.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-16 09:35 UTC by David
Modified: 2009-07-17 00:17 UTC (History)
1 user (show)

See Also:
Host:
Target: i386-uclibc
Build:


Attachments
Fix (1.79 KB, patch)
2009-07-16 22:34 UTC, Denys Vlasenko
Details

Note You need to log in before you can comment on or make changes to this bug.
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