~/test(1)
en
NAME
test, [ - ask a question about a file or a string
SYNOPSIS
test expression | [ expression ]
DESCRIPTION
Answers a question by the only means a command has: its exit status, 0 for
yes. That is why it is what if and && are usually asking, and why it
prints nothing at all.
[ is the same command under the name that reads better in an if, and it
insists on a closing ] for the same reason. ! in front of the expression
turns the answer over.
The file questions read the same mode bits ls -l prints and chmod
changes, so [ -w about.md ] is false for a guest and true for the owner —
which is the whole of man su in one expression.
OPTIONS
- -e
- it is there
- -f
- it is there and is a file
- -d
- it is there and is a directory
- -r
- you may read it, which is the mode bit ls -l shows
- -w
- you may write it
- -x
- you may run it
- -s
- it has something in it
- -z
- the string is empty
- -n
- the string is not empty
- =, !=
- two strings, the same or not
- -eq
- the numbers are equal
- -ne
- the numbers are not equal
- -lt
- less than
- -le
- less than or equal
- -gt
- greater than
- -ge
- greater than or equal
EXAMPLES
test -f about.md
[ -d /tmp ] && echo writable
[ "$USER" = tilen ]
if [ -r .zsh_history ]; then cat .zsh_history; fi