GNU Info

Info Node: (bashref.info)Bash Conditional Expressions

(bashref.info)Bash Conditional Expressions


Next: Shell Arithmetic Prev: Interactive Shells Up: Bash Features
Enter node , (file) or (file)node

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.

`-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 a regular file.

`-g FILE'
     True if FILE exists and its set-group-id bit is set.

`-h FILE'
     True if FILE exists and is a symbolic link.

`-k FILE'
     True if FILE exists and its "sticky" bit is set.

`-p FILE'
     True if FILE exists and is a named pipe (FIFO).

`-r FILE'
     True if FILE exists and is readable.

`-s FILE'
     True if FILE exists and has a size greater than zero.

`-t FD'
     True if file descriptor FD is open and refers to a terminal.

`-u FILE'
     True if FILE exists and its set-user-id bit is set.

`-w FILE'
     True if FILE exists and is writable.

`-x FILE'
     True if FILE exists and is executable.

`-O FILE'
     True if FILE exists and is owned by the effective user id.

`-G FILE'
     True if FILE exists and is owned by the effective group id.

`-L FILE'
     True if FILE exists and is a symbolic link.

`-S FILE'
     True if FILE exists and is a socket.

`-N FILE'
     True if FILE exists and has been modified since it was last read.

`FILE1 -nt FILE2'
     True if FILE1 is newer (according to modification date) than FILE2.

`FILE1 -ot FILE2'
     True if FILE1 is older than FILE2.

`FILE1 -ef FILE2'
     True if FILE1 and FILE2 have the same device and inode numbers.

`-o OPTNAME'
     True if shell option OPTNAME is enabled.  The list of options
     appears in the description of the `-o' option to the `set' builtin
     (Note: The Set Builtin).

`-z STRING'
     True if the length of STRING is zero.

`-n STRING'
`STRING'
     True if the length of STRING is non-zero.

`STRING1 == STRING2'
     True if the strings are equal.  `=' may be used in place of `=='.

`STRING1 != STRING2'
     True if the strings are not equal.

`STRING1 < STRING2'
     True if STRING1 sorts before STRING2 lexicographically in the
     current locale.

`STRING1 > STRING2'
     True if STRING1 sorts after STRING2 lexicographically in the
     current locale.

`ARG1 OP ARG2'
     `OP' is 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.


automatically generated by info2www version 1.2.2.9