integer comparison operators
The test operators that compare whole numbers: -eq equal, -ne not equal, -lt less than, -le at most, -gt greater than and -ge at least.
In more detail
Inside [ ] and [[ ]] the symbols < and > compare text alphabetically, not numbers, which is why these letter operators exist. Inside (( )) you can write the usual < and > for numbers.
Example
if [[ $count -gt 0 ]]; then echo positive; fiRelated terms
- test command — The test command, also written with single square brackets, that checks a condition such as a file existing or two values being equal, and exits 0 if it holds.
- double brackets — Bash's double-bracket test, [[ and ]], a keyword that does not split words or expand globs and adds pattern and regular expression matching.
- arithmetic expansion — Evaluating whole-number maths inside $(( )) and replacing it with the result; (( )) on its own evaluates without printing anything.
Taught in
- Exit Codes, And What Success Means — Bash Scripting & Command Line Automation
- Conditionals: test, Brackets, Double Brackets, case — Bash Scripting & Command Line Automation
- Loops: for, while, until, break, continue — Bash Scripting & Command Line Automation
- Functions, local And declare — Bash Scripting & Command Line Automation
- Arguments: Dollar One, Dollar At, shift — Bash Scripting & Command Line Automation
- trap, Cleanup And Temporary Files — Bash Scripting & Command Line Automation
- ShellCheck — Bash Scripting & Command Line Automation
- POSIX sh Versus Bash — Bash Scripting & Command Line Automation