bash: Bash Conditional Expressions

 
 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.  Bash handles several filenames specially
 when they are used in expressions.  If the operating system on which
 Bash is running provides these special files, Bash will use them;
 otherwise it will emulate them internally with this behavior: 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 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.
 
 '-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.
 
 '-N FILE'
      True if FILE exists and has been modified since it was last read.
 
 '-O FILE'
      True if FILE exists and is owned by the effective user id.
 
 '-S FILE'
      True if FILE exists and is a socket.
 
 'FILE1 -ef FILE2'
      True if FILE1 and FILE2 refer to the same device and inode numbers.
 
 'FILE1 -nt FILE2'
      True if FILE1 is newer (according to modification date) than FILE2,
      or if FILE1 exists and FILE2 does not.
 
 'FILE1 -ot FILE2'
      True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
      does not.
 
 '-o OPTNAME'
      True if the shell option OPTNAME is enabled.  The list of options
      appears in the description of the '-o' option to the 'set' builtin
      (SeeThe Set Builtin).
 
 '-v VARNAME'
      True if the shell variable VARNAME is set (has been assigned a
      value).
 
 '-R VARNAME'
      True if the shell variable VARNAME is set and is a name reference.
 
 '-z STRING'
      True if the length of STRING is zero.
 
 '-n STRING'
 'STRING'
      True if the length of STRING is non-zero.
 
 'STRING1 == STRING2'
 'STRING1 = STRING2'
      True if the strings are equal.  When used with the '[[' command,
      this performs pattern matching as described above (See
      Conditional Constructs).
 
      '=' should be used with the 'test' command for POSIX conformance.
 
 'STRING1 != STRING2'
      True if the strings are not equal.
 
 'STRING1 < STRING2'
      True if STRING1 sorts before STRING2 lexicographically.
 
 'STRING1 > STRING2'
      True if STRING1 sorts after STRING2 lexicographically.
 
 '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.