I'm having a tough time wrapping my soggy little brain around the various usages of [
]
, quoted vars and -eq
vs ==
.
What is the difference between these statements? Is it as simple as one is more posix compliant than the other or is there a functional difference I should worry about?
[ ! -z "$var" ] && echo "Not empty" || echo "Empty"
[[ ! -z "$var" ]] && echo "Not empty" || echo "Empty"
and what about:
if "$report" == "1"; then blah; fi
vs
if [ "$report" == "1" ]; then blah; fi
vs
[ "$report" -eq 1 ]; then blah
I get that [
is a test function in the shell but I don't understand when I need to start with if
or when that isn't necessary.