Hi Bastian,

2015-06-24 23:03 GMT+02:00 Bastian Bittorf <[email protected]>:
> we stumbled over an interesting behaviour,
> which is the same like in bash, but new to us:
>
> root@box:~ a=120; echo $(( a / 60 )); echo HERE
> 2
> HERE
>
> root@box:~ a=; echo $(( a / 60 )); echo HERE
> 0
> HERE
>
> root@box:~ a=; echo $(( $a / 60 )); echo HERE
> -ash: arithmetic syntax error
>
> root@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_,,_
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to