I was demonstrating a piece of funny code (or so I think) to my students in class, and to my surprise, it did not work in zsh
. I then switched to bash
and it worked as expected.
The code is the following:
[ $(( $RANDOM % 6 )) == 0 ] && echo "Boom" || echo "Click"
In bash
it prints Boom
or Click
randomly, as expected. But in zsh
I get the error message below:
zsh: = not found
Can anyone explain what is the difference? To my understanding, both shells should interpret scripts in an equivalent manner.
Thanks.
-eq
anyhow? Or perhaps use the arithmetic expression directly i.e.(( $RANDOM % 6 == 0 )) && echo "Boom" || echo "Click"
$
before the variable name could (should?) be removed. And, since in C the result of an arithmetic expression is a valid result which (if 0) will generate an exit code of 1 (0 otherwise). Then:((RANDOM%6)) && echo Click || echo Boom
should be plenty.