While learning a bit about bash, I come to see four types of ways of working with if
statements:
The tests you had listed :
test
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