While learning a bit about bash, I come to see four types of ways of working with if statements:
- Single Parenthesis – ( … )
- Double Parenthesis – (( … ))
- Single Square Bracket – [ … ]
- Double Square Brackets – [[ … ]]
What is the difference between Parenthesis and Square Brackets in bash.
The tests you had listed :
testtestbut more powerful)are not exhaustive, you can use boolean logic
too, because the commands have exit status. In
bash,0istrueand >0isfalse.You can see the exit status like this :
See :
http://wiki.bash-hackers.org/syntax/basicgrammar
http://wiki.bash-hackers.org/syntax/arith_expr
http://mywiki.wooledge.org/BashGuide/TestsAndConditionals