ash bug ?

Juergen Hennerich juergen at hennerich.eu
Mon Sep 4 08:43:35 UTC 2006


walter harms schrieb:
> this is a short version of arithmetic expansion ( let "x=5+y" == (( x=5+y)) ) (no POSIX feature
> book but it seems a common feature in shells according to my book ).
>  the problem is that this is supported. only the additional spaces
> around '==' causing the problem.
> 
a)
Why do you think, that spaces in an (unquoted) expression are supported. 
This is not C!
b)
I already said, that it doesn't work. (It looks indeed that it should 
work, but is broken for some reason). You just haven't noticed that, 
because your test was useless.

~ $ x=4
~ $ if (( x == 4 )) ; then echo TRUE ; else echo FALSE ; fi
ash: x: not found
FALSE
~ $ if (( x==4 )) ; then echo TRUE ; else echo FALSE ; fi
TRUE
~ $ x=2
~ $ if (( x==4 )) ; then echo TRUE ; else echo FALSE ; fi
TRUE
~ $ echo $x
2
~ $
~ $ if (( some_undefined_var==some_value )) ; then echo TRUE ; else echo 
FALSE ; fi
TRUE
~ $

You can see here, that it always evaluates to TRUE.

~ $ if ( let x == 2 ) ; then echo TRUE ; else echo FALSE ; fi
ash: let: Syntax error: ==
FALSE

~ $ if ( let x==2 ) ; then echo TRUE ; else echo FALSE ; fi
TRUE
~ $ if ( let x==4 ) ; then echo TRUE ; else echo FALSE ; fi
FALSE
~ $ if ( let "x == 4" ) ; then echo TRUE ; else echo FALSE ; fi
FALSE
~ $ if ( let "x == 2" ) ; then echo TRUE ; else echo FALSE ; fi
TRUE

Here you can see, that you have to properly quote the expression. In 
this respect, there is also no difference to bash,ksh,zsh,....

Juergen

> re,
>  wh
> 
> 
> Rich Felker wrote:
>> On Sun, Sep 03, 2006 at 08:40:22PM +0200, walter harms wrote:
>>> hi list,
>>> riaz and i are working on documenting ash. so i tried to run the bash test scripts on ash.
>>> and one place ash breaks where sh works. bug or feature ?
>>> ash is running endless because it does not find 'x'
>>>
>>> x=3
>>> until (( x == 4 )) ; do
>>>         x=4
>>> done
>>>
>>> note:
>>>
>>> removing the spaces solves the problem.
>> See http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
>> Nothing about (( )) there.
>>
>> Rich
>>



More information about the busybox mailing list