String Operators
String ordering is affected by the current locale. The clearest way to use
< and > is inside [[ ]]:
[ ], but the operators must be escaped so the shell does not treat them as redirections:
[ ], quoting variable expansions prevents word splitting and pathname expansion and safely handles empty values:
[[ ]], quoting the left-hand variable is usually unnecessary because those expansions do not undergo word splitting or pathname expansion:
Integer Operators
File Operators
These check properties of files and directories. We use them a lot in scripts that interact with the filesystem:Logical Operators
We combine them to build more complex conditions. Example:
${#var} gives us the string length directly. Using echo "$var" | wc -m would also count the newline printed by echo.