[BusyBox 0001380]: /usr/bin/[ gives "[: ]: unknown operand" message
bugs at busybox.net
bugs at busybox.net
Fri Jun 8 00:34:04 PDT 2007
The following issue has been CLOSED
======================================================================
http://busybox.net/bugs/view.php?id=1380
======================================================================
Reported By: dmaizer
Assigned To: BusyBox
======================================================================
Project: BusyBox
Issue ID: 1380
Category: Other
Reproducibility: always
Severity: major
Priority: normal
Status: closed
Resolution: open
Fixed in Version:
======================================================================
Date Submitted: 06-05-2007 08:44 PDT
Last Modified: 06-08-2007 00:34 PDT
======================================================================
Summary: /usr/bin/[ gives "[: ]: unknown operand" message
Description:
We are working in an Apache (httpd 2.2.3) suexec CGI scripts environment
and our CGI scripts need to provide full paths to all applets/programs
used, so we have something like the following in the CGI script:
if /usr/bin/[ $# -lt 1 ]; then
/bin/echo "sitediag: too few arguments"
/bin/echo "Try sitediag --help for more information"
exit 1
fi
However - this gives the error:
[: ]: unknown operand
Meaning that the "]" closing bracket is being recognized as an unknown
operand. But of course this bracket is needed to close the test...
If we remove the /usr/bin prefix from [ - then it works and gives the
expected echo messages above.
I tried looking at busybox code (being no expert of that code) and found
the following in coreutils/test.c:
if (*t_wp != NULL && *++t_wp != NULL) {
bb_error_msg("%s: unknown operand", *t_wp);
return 2;
}
My guess is that somehow using the pathname causes that condition above to
be true, but I haven't been able to find out why yet (I started looking
from ash.c and "lower" to see why this happens, but haven't been able to
find anything meaningful so far - hopefully someone who knows the code
better can provide a clue or a fix.
======================================================================
----------------------------------------------------------------------
dmaizer - 06-05-07 08:45
----------------------------------------------------------------------
We use version 1.4.2 of busybox...
----------------------------------------------------------------------
bernhardf - 06-05-07 09:26
----------------------------------------------------------------------
confirmed.
As a quick workaround, just use "test" instead of "[" or "[[".
I will also note, that the check for surplus args is borked (as you note)
since some closing brackets are a legit character to see -- IFF we were
called as "[" one and two otherwise.
For the sake of code-size, there is currently no checking for the correct
number of closing brackets, so just omitting any closing bracket bypasses
the reported behaviour.
----------------------------------------------------------------------
vda - 06-08-07 00:34
----------------------------------------------------------------------
Fixed in rev 18775, thanks
Issue History
Date Modified Username Field Change
======================================================================
06-05-07 08:44 dmaizer New Issue
06-05-07 08:44 dmaizer Status new => assigned
06-05-07 08:44 dmaizer Assigned To => BusyBox
06-05-07 08:45 dmaizer Note Added: 0002442
06-05-07 09:26 bernhardf Note Added: 0002443
06-08-07 00:34 vda Status assigned => closed
06-08-07 00:34 vda Note Added: 0002464
======================================================================
More information about the busybox-cvs
mailing list