Go to the first, previous, next, last section, table of contents.
A conditional expression is used with the [[
compound
command to test attributes of files and to compare strings. Each
expression can be constructed from one or more of the following unary or
binary expressions:
-a file
-
True if file exists.
-b file
-
True if file exists and is a block special file.
-c file
-
True if file exists and is a character special file.
-d file
-
True if file exists and is a directory.
-e file
-
True if file exists.
-f file
-
True if file exists and is an ordinary file.
-g file
-
True if file exists and has its setgid bit set.
-h file
-
True if file exists and is a symbolic link.
-k file
-
True if file exists and has its sticky bit set.
-n string
-
True if length of string is non-zero.
-o option
-
True if option named option is on. option may be a
single character, in which case it is a single letter option name.
See section Specifying Options.
-p file
-
True if file exists and is a FIFO special file or a pipe.
-r file
-
True if file exists and is readable by the current process.
-s file
-
True if file exists and has size greater than zero.
-t fd
-
True if file descriptor number fd is open and associated with a
terminal device (note: fd is not optional).
-u file
-
True if file exists and has its setuid bit set.
-w file
-
True if file exists and is writable by current process.
-x file
-
True if file exists and is executable by current process. If
file exists and is a directory, then the current process has
permission to search in the directory.
-z string
-
True if length of string is zero.
-L file
-
True if file exists and is a symbolic link.
-O file
-
True if file exists and is owned by the effective user id of this
process.
-G file
-
True if file exists and its group matches the effective group id
of this process.
-S file
-
True if file exists and is a socket.
-N file
-
True if file exists and its access time is not newer than its
modification time.
file1 -nt file2
-
True if file1 exists and is newer than file2.
file1 -ot file2
-
True if file1 exists and is older than file2.
file1 -ef file2
-
True if file1 and file2 exist and refer to the same file.
string == pattern
-
string = pattern
-
True if string matches pattern. The first form is the
preferred one. The other form is for backward compatibility and should
be considered obsolete.
string != pattern
-
True if string does not match pattern.
string1 < string2
-
True if string1 comes before string2 based on ASCII value of
their characters.
string1 > string2
-
True if string1 comes after string2 based on ASCII value of
their characters.
exp1 -eq exp2
-
True if exp1 is equal to exp2.
exp1 -ne exp2
-
True if exp1 is not equal to exp2.
exp1 -lt exp2
-
True if exp1 is less than exp2.
exp1 -gt exp2
-
True if exp1 is greater than exp2.
exp1 -le exp2
-
True if exp1 is less than or equal to exp2.
exp1 -ge exp2
-
True if exp1 is greater than or equal to exp2.
( exp )
-
True if exp is true.
! exp
-
True if exp is false.
exp1 && exp2
-
True if exp1 and exp2 are both true.
exp1 || exp2
-
True if either exp1 or exp2 is true.
In each of the above expressions, if file is of the form
`/dev/fd/n', where n is an integer, then the test is
applied to the open file whose descriptor number is n, even if
the underlying system does not support the `/dev/fd'
directory.
Go to the first, previous, next, last section, table of contents.