Bash Test Operators Reference
Interactive reference for Bash conditional test operators: file, string, and integer comparisons in [ ... ] and [[ ... ]].
Search by symbol, by name, or by the question you are trying to ask. Press / to jump here.
44 of 44 operators shown
Paste one whole expression, up to 512 characters. Nothing is executed and no file is touched — the brackets are parsed, not run.
Paste a test expression above to have each operator named, with the construct it belongs to and the traps that come with it.
Everything on this page is computed in the page itself. No expression is sent anywhere, and nothing here runs a shell or touches a file.
Do it offline:$
How to use it
- Use the category filter tabs (File, String, Numeric) or type in the search bar to locate specific test operators.
- Inspect the compatibility badges to verify if the operator is supported under POSIX sh `[ ... ]` or requires Bash `[[ ... ]]`.
- Click the copy button beside any code example to directly use safe, pre-quoted conditional syntax in your bash scripts.
Comprehensive interactive reference for Bash and POSIX test operators. Compare conditional file tests, string evaluations, and integer arithmetic between [ ... ] and [[ ... ]].
How it works
In UNIX shells, the single bracket `[` is actually a command alias for `test`. Because it is an external command, arguments undergo pathname expansion and word splitting, requiring strict variable quoting.
The double bracket `[[ ... ]]` is a Bash reserved keyword. It prevents word splitting, supports extended regular expression matching with `=~`, and allows pattern matching using `==`.
Numeric comparisons in shell scripts use `-eq`, `-ne`, `-lt`, `-gt` flags because `<` and `>` are interpreted as I/O redirection operators inside `[ ... ]`.
All documentation examples and rules are rendered deterministically client-side without network requests.
Examples
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Common errors
FAQ
Why should I prefer [[ ]] over [ ] in modern Bash scripts?
Double brackets `[[ ]]` prevent unexpected bugs caused by unquoted variables expanding into multiple words or empty strings. They also support regular expression matching (`=~`) and logical `&&` / `||` inside the test expression.
What is the difference between -z and -n in bash test conditions?
`-z` returns true if a string is empty (zero length). `-n` returns true if a string is not empty (length greater than zero). Always wrap variables in quotes (e.g. `[ -z "$VAR" ]`) to avoid syntax errors when variables are unset.
Why do < and > operators behave unexpectedly in [ ]?
Inside single brackets `[ ]`, `<` and `>` redirect input/output to files on your filesystem. In double brackets `[[ ]]`, `<` and `>` compare strings lexicographically without redirection.