[BusyBox] bug in BB hush 'elif'

Robin Gilks robin.gilks at tait.co.nz
Mon Mar 15 02:05:51 UTC 2004


Greetings

I've been trying to use hush shell to implement a reasonably tidy 
implementation of a switch statement but there appears to be a bug in 
the operation of the elif sub-command. The example below illustrates the 
problem. The same can be seen in the u-boot bootloader variant of hush 
as well.

/ # if true; then echo "one"; elif true; then echo "two"; elif true; 
then echo "three"; else echo "four"; fi

one
two
three
/ #


It looks like the condition of the 'elif' statements can be any old 
garbage as indicated by the following:

/ # if true; then echo "one"; elif xxx; then echo "two"; elif yyy; then 
echo "three"; else echo "four"; fi
one
two
three
/ #

interestingly, if the first condition is rubbish, the rest are parsed as 
garbage correctly!!!

/ # if aaa; then echo "one"; elif xxx; then echo "two"; elif yyy; then 
echo "three"; else echo "four"; fi
hush: couldn't exec: aaa: No such file or directory
hush: couldn't exec: xxx: No such file or directory
hush: couldn't exec: yyy: No such file or directory
four
/ #


Could someone assist in the navigating of this module - the why of it 
that is - I assume it should be ignoring everything up to a 'fi' once it 
has hit a true condition but instead it executes all the clauses in the 
'elif' statements as well!!


Many thanks

-- 
Robin Gilks
Senior Design Engineer          Phone: (+64)(3) 357 1569
Tait Electronics                Fax  :  (+64)(3) 359 4632
PO Box 1645 Christchurch        Email : robin.gilks at tait.co.nz
New Zealand




More information about the busybox mailing list