| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.4 Bash Conditional Expressions
Conditional expressions are used by the [[ compound command
and the test and [ builtin commands.
Expressions may be unary or binary. Unary expressions are often used to examine the status of a file. There are string operators and numeric comparison operators as well. If the file argument to one of the primaries is of the form ‘/dev/fd/N’, then file descriptor N is checked. If the file argument to one of the primaries is one of ‘/dev/stdin’, ‘/dev/stdout’, or ‘/dev/stderr’, file descriptor 0, 1, or 2, respectively, is checked.
When used with [[, the ‘<’ and ‘>’ operators sort
lexicographically using the current locale.
The test command uses ASCII ordering.
Unless otherwise specified, primaries that operate on files follow symbolic links and operate on the target of the link, rather than the link itself.
-a fileTrue if file exists.
-b fileTrue if file exists and is a block special file.
-c fileTrue if file exists and is a character special file.
-d fileTrue if file exists and is a directory.
-e fileTrue if file exists.
-f fileTrue if file exists and is a regular file.
-g fileTrue if file exists and its set-group-id bit is set.
-h fileTrue if file exists and is a symbolic link.
-k fileTrue if file exists and its "sticky" bit is set.
-p fileTrue if file exists and is a named pipe (FIFO).
-r fileTrue if file exists and is readable.
-s fileTrue if file exists and has a size greater than zero.
-t fdTrue if file descriptor fd is open and refers to a terminal.
-u fileTrue if file exists and its set-user-id bit is set.
-w fileTrue if file exists and is writable.
-x fileTrue if file exists and is executable.
-G fileTrue if file exists and is owned by the effective group id.
-L fileTrue if file exists and is a symbolic link.
-N fileTrue if file exists and has been modified since it was last read.
-O fileTrue if file exists and is owned by the effective user id.
-S fileTrue if file exists and is a socket.
file1 -ef file2True if file1 and file2 refer to the same device and inode numbers.
file1 -nt file2True if file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not.
file1 -ot file2True if file1 is older than file2, or if file2 exists and file1 does not.
-o optnameTrue if the shell option optname is enabled. The list of options appears in the description of the ‘-o’ option to the
setbuiltin (see section The Set Builtin).-v varnameTrue if the shell variable varname is set (has been assigned a value).
-R varnameTrue if the shell variable varname is set and is a name reference.
-z stringTrue if the length of string is zero.
-n stringstringTrue if the length of string is non-zero.
string1 == string2string1 = string2True if the strings are equal. When used with the
[[command, this performs pattern matching as described above (see section Conditional Constructs).‘=’ should be used with the
testcommand for POSIX conformance.string1 != string2True if the strings are not equal.
string1 < string2True if string1 sorts before string2 lexicographically.
string1 > string2True if string1 sorts after string2 lexicographically.
arg1 OP arg2OPis one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge’. These arithmetic binary operators return true if arg1 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to arg2, respectively. Arg1 and arg2 may be positive or negative integers.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on February 28, 2014 using texi2html 5.0.
