Difference between parentheses and brackets in Bash conditionals

The tests you had listed :

  • Single Parenthesis – ( … ) is creating a subshell
  • Double Parenthesis – (( … )) is for arithmetic operation
  • Single Square Bracket – [ … ] is the syntax for the POSIX test
  • Double Square Brackets – [[ … ]] is the syntax for bash conditional expressions (similar to test but more powerful)

are not exhaustive, you can use boolean logic

if command; then ...

too, because the commands have exit status. In bash, 0 is true and > 0 is false.

You can see the exit status like this :

command
echo $?

See :

http://wiki.bash-hackers.org/syntax/basicgrammar
http://wiki.bash-hackers.org/syntax/arith_expr
http://mywiki.wooledge.org/BashGuide/TestsAndConditionals

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)