|
CONDITIONAL EXPRESSIONS
Up
Next
Previous
CONDITIONAL EXPRESSIONS
Conditional expressions are used by the [[\fP compound command and
the test\fP and [\fP builtin commands to test file attributes
and perform string and arithmetic comparisons.
Expressions are formed from the following unary or binary primaries.
If any file\fP argument to one of the primaries is of the form
/dev/fd/n\fP, then file descriptor n\fP is checked.
If the file\fP argument to one of the primaries is one of
/dev/stdin\fP, /dev/stdout\fP, or /dev/stderr\fP, file
descriptor 0, 1, or 2, respectively, is checked.
.sp 1
-
-a file\fP
-
True if file\fP exists.
-
-b file\fP
-
True if file\fP exists and is a block special file.
-
-c file\fP
-
True if file\fP exists and is a character special file.
-
-d file\fP
-
True if file\fP exists and is a directory.
-
-e file\fP
-
True if file\fP exists.
-
-f file\fP
-
True if file\fP exists and is a regular file.
-
-g file\fP
-
True if file\fP exists and is set-group-id.
-
-h file\fP
-
True if file\fP exists and is a symbolic link.
-
-k file\fP
-
True if file\fP exists and its ``sticky'' bit is set.
-
-p file\fP
-
True if file\fP exists and is a named pipe (FIFO).
-
-r file\fP
-
True if file\fP exists and is readable.
-
-s file\fP
-
True if file\fP exists and has a size greater than zero.
-
-t fd\fP
-
True if file descriptor
fd
is open and refers to a terminal.
-
-u file\fP
-
True if file\fP exists and its set-user-id bit is set.
-
-w file\fP
-
True if file\fP exists and is writable.
-
-x file\fP
-
True if file\fP exists and is executable.
-
-O file\fP
-
True if file\fP exists and is owned by the effective user id.
-
-G file\fP
-
True if file\fP exists and is owned by the effective group id.
-
-L file\fP
-
True if file\fP exists and is a symbolic link.
-
-S file\fP
-
True if file\fP exists and is a socket.
-
-N file\fP
-
True if file\fP exists and has been modified since it was last read.
-
file1\fP -nt\fP file2\fP
-
True if file1\fP is newer (according to
modification date) than file2\fP.
-
file1\fP -ot\fP file2\fP
-
True if file1\fP is older than file2\fP.
-
file1\fP -ef\fP file2\fP
-
True if file1\fP and file2\fP have the same device and
inode numbers.
-
-o optname\fP
-
True if shell option
optname
is enabled.
See the list of options under the description of the
-o
option to the
set
builtin below.
-
-z string\fP
-
True if the length of string\fP is zero.
-
-n string\fP
-
-
string\fP
-
True if the length of
string
is non-zero.
-
string1\fP ==\fP string2\fP
-
True if the strings are equal. =\fP may be used in place of
==\fP.
-
string1\fP !=\fP string2\fP
-
True if the strings are not equal.
-
string1\fP <\fP string2\fP
-
True if string1\fP sorts before string2\fP lexicographically
in the current locale.
-
string1\fP >\fP string2\fP
-
True if string1\fP sorts after string2\fP lexicographically
in the current locale.
-
arg1\fP OP\fP arg2\fP
-
.SM
OP
is one of
.BR -eq ,
.BR -ne ,
.BR -lt ,
.BR -le ,
.BR -gt ,
or
.BR -ge .
These arithmetic binary operators return true if arg1\fP
is equal to, not equal to, less than, less than or equal to,
greater than, or greater than or equal to arg2\fP, respectively.
Arg1
and
arg2
may be positive or negative integers.
Up
Next
Previous