Name
test
Synopsis
test
condition
[
condition
]
Evaluate a condition and, if its value is
true, return a zero exit status; otherwise, return a nonzero exit
status. An alternate form of the command uses [ ] rather than the
word test. condition is constructed using
the following expressions. Conditions are true if the description
holds true.
File conditions
- -a
file fileexists.- -b
file fileis a block special file.- -c
file fileis a character special file.- -d
file fileis a directory.- -e
file fileexists.- -f
file fileis a regular file.- -g
file filehas the set-group-ID bit set.- -h
file fileis a symbolic link.- -k
file filehas its sticky bit (no longer used) set.- -p
file fileis a named pipe (FIFO).- -r
file fileis readable.- -s
file filehas a size greater than 0.- -t [n]
The open file descriptor n is associated with a terminal device (default
nis 1).- -u
file filehas its set-user-ID bit set.- -w
file fileis writable.- -x
file fileis executable.- -G
file file’s group is the process’s effective GID.- -L
file fileis a symbolic link.- -N
file filehas been modified since its last time of access.- -O
file file’s owner is the process’s effective UID.- -S
file fileis a socket.-
f1-eff2 Files
f1andf2are linked (refer to the same file through a hard link).-
f1-ntf2 File
f1is newer thanf2.-
f1-otf2 File
f1is older thanf2.
String conditions
- -n
s1 String
s1has nonzero length.- -o
s1 Shell option
s1is set. Shell options are described under the set built-in command.- -z
s1 String
s1has 0 length. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access