bash: Bash Conditional Expressions

1 
1 6.4 Bash Conditional Expressions
1 ================================
1 
1 Conditional expressions are used by the '[[' compound command and the
1 'test' and '[' builtin commands.
1 
1    Expressions may be unary or binary.  Unary expressions are often used
1 to examine the status of a file.  There are string operators and numeric
1 comparison operators as well.  Bash handles several filenames specially
1 when they are used in expressions.  If the operating system on which
1 Bash is running provides these special files, Bash will use them;
1 otherwise it will emulate them internally with this behavior: If the
1 FILE argument to one of the primaries is of the form '/dev/fd/N', then
1 file descriptor N is checked.  If the FILE argument to one of the
1 primaries is one of '/dev/stdin', '/dev/stdout', or '/dev/stderr', file
1 descriptor 0, 1, or 2, respectively, is checked.
1 
1    When used with '[[', the '<' and '>' operators sort lexicographically
1 using the current locale.  The 'test' command uses ASCII ordering.
1 
1    Unless otherwise specified, primaries that operate on files follow
1 symbolic links and operate on the target of the link, rather than the
1 link itself.
1 
1 '-a FILE'
1      True if FILE exists.
1 
1 '-b FILE'
1      True if FILE exists and is a block special file.
1 
1 '-c FILE'
1      True if FILE exists and is a character special file.
1 
1 '-d FILE'
1      True if FILE exists and is a directory.
1 
1 '-e FILE'
1      True if FILE exists.
1 
1 '-f FILE'
1      True if FILE exists and is a regular file.
1 
1 '-g FILE'
1      True if FILE exists and its set-group-id bit is set.
1 
1 '-h FILE'
1      True if FILE exists and is a symbolic link.
1 
1 '-k FILE'
1      True if FILE exists and its "sticky" bit is set.
1 
1 '-p FILE'
1      True if FILE exists and is a named pipe (FIFO).
1 
1 '-r FILE'
1      True if FILE exists and is readable.
1 
1 '-s FILE'
1      True if FILE exists and has a size greater than zero.
1 
1 '-t FD'
1      True if file descriptor FD is open and refers to a terminal.
1 
1 '-u FILE'
1      True if FILE exists and its set-user-id bit is set.
1 
1 '-w FILE'
1      True if FILE exists and is writable.
1 
1 '-x FILE'
1      True if FILE exists and is executable.
1 
1 '-G FILE'
1      True if FILE exists and is owned by the effective group id.
1 
1 '-L FILE'
1      True if FILE exists and is a symbolic link.
1 
1 '-N FILE'
1      True if FILE exists and has been modified since it was last read.
1 
1 '-O FILE'
1      True if FILE exists and is owned by the effective user id.
1 
1 '-S FILE'
1      True if FILE exists and is a socket.
1 
1 'FILE1 -ef FILE2'
1      True if FILE1 and FILE2 refer to the same device and inode numbers.
1 
1 'FILE1 -nt FILE2'
1      True if FILE1 is newer (according to modification date) than FILE2,
1      or if FILE1 exists and FILE2 does not.
1 
1 'FILE1 -ot FILE2'
1      True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
1      does not.
1 
1 '-o OPTNAME'
1      True if the shell option OPTNAME is enabled.  The list of options
1      appears in the description of the '-o' option to the 'set' builtin
1      (⇒The Set Builtin).
1 
1 '-v VARNAME'
1      True if the shell variable VARNAME is set (has been assigned a
1      value).
1 
1 '-R VARNAME'
1      True if the shell variable VARNAME is set and is a name reference.
1 
1 '-z STRING'
1      True if the length of STRING is zero.
1 
1 '-n STRING'
1 'STRING'
1      True if the length of STRING is non-zero.
1 
1 'STRING1 == STRING2'
1 'STRING1 = STRING2'
1      True if the strings are equal.  When used with the '[[' command,
11      this performs pattern matching as described above (⇒
      Conditional Constructs).
1 
1      '=' should be used with the 'test' command for POSIX conformance.
1 
1 'STRING1 != STRING2'
1      True if the strings are not equal.
1 
1 'STRING1 < STRING2'
1      True if STRING1 sorts before STRING2 lexicographically.
1 
1 'STRING1 > STRING2'
1      True if STRING1 sorts after STRING2 lexicographically.
1 
1 'ARG1 OP ARG2'
1      'OP' is one of '-eq', '-ne', '-lt', '-le', '-gt', or '-ge'.  These
1      arithmetic binary operators return true if ARG1 is equal to, not
1      equal to, less than, less than or equal to, greater than, or
1      greater than or equal to ARG2, respectively.  ARG1 and ARG2 may be
1      positive or negative integers.
1