ash / shell scripting question / abort after Arithmetic Evaluation
Xabier Oneca -- xOneca
xoneca at gmail.com
Wed Jun 24 22:12:02 UTC 2015
Hi Bastian,
2015-06-24 23:03 GMT+02:00 Bastian Bittorf <bittorf at bluebottle.com>:
> we stumbled over an interesting behaviour,
> which is the same like in bash, but new to us:
>
> root at box:~ a=120; echo $(( a / 60 )); echo HERE
> 2
> HERE
>
> root at box:~ a=; echo $(( a / 60 )); echo HERE
> 0
> HERE
>
> root at box:~ a=; echo $(( $a / 60 )); echo HERE
> -ash: arithmetic syntax error
>
> root at box:~ echo $(( / 60 )); echo HERE
> -ash: arithmetic syntax error
>
> can somebody explain, why the execution stopped
> totally in the last 2 examples? this was the root-cause
> for a not removed 'lock'-dir in one of our scripts...
I think it is copied from Bash behavior. According to bash(1) doc:
(section ARITHMETIC EVALUATION)
> A shell variable that is null or unset evaluates to 0 when referenced by name without using the parameter expansion syntax.
The last example is a *true* syntax error (the numerator is missing in
the division). The third is equivalent to the last because `$a` is
empty and being replaced with nothing.
Cheers,
Xabier Oneca_,,_
More information about the busybox
mailing list