Thanks for this valuable article. So many of us use bash scripting without ever properly learning it.
I want to point out that, in a Boolean context, the (( )) is an evaluation of the contained expression, not the exit code of the double parens itself. For example:
if (( 2 - 2 )) # false (0)
then
echo hi
else
echo die
fi
Even though the exit code of (( 2 - 2 )) is 1 (true), this outputs die since the evaluation of the expression 2 - 2 is 0.
Note that (( (( 2 - 2 )) )) would, however, be false, since the evaluation of (( 2 - 2 )) is its exit code.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for this valuable article. So many of us use bash scripting without ever properly learning it.
I want to point out that, in a Boolean context, the
(( ))
is an evaluation of the contained expression, not the exit code of the double parens itself. For example:Even though the exit code of
(( 2 - 2 ))
is 1 (true), this outputsdie
since the evaluation of the expression 2 - 2 is 0.Note that
(( (( 2 - 2 )) ))
would, however, be false, since the evaluation of(( 2 - 2 ))
is its exit code.