file test operators
Test operators that ask about a path: -e exists, -f regular file, -d directory, -s not empty, -r, -w and -x readable, writable and executable.
In more detail
They work in both [ ] and [[ ]]. Testing before acting is only a hint, because the file can change between the test and your command, so still check the command's own status.
Example
[ -d "$work" ] && echo "still there"Related 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.
Taught in
- Conditionals: test, Brackets, Double Brackets, case — Bash Scripting & Command Line Automation
- trap, Cleanup And Temporary Files — Bash Scripting & Command Line Automation
- Debugging: set -x, bash -n And Reading The Error — Bash Scripting & Command Line Automation
- Permissions And Ownership — Bash Scripting & Command Line Automation