DEV Community

Discussion on: Bash Brackets Quick Reference

Collapse
 
thebeartiger profile image
John Harrington

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
Enter fullscreen mode Exit fullscreen mode

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