GNU Info

Info Node: (zsh.info)Conditional Expressions

(zsh.info)Conditional Expressions


Next: Prompt Expansion Prev: Arithmetic Evaluation Up: Top
Enter node , (file) or (file)node

Conditional Expressions
***********************

A _conditional expression_ is used with the [[ compound command to test
attributes of files and to compare strings.  Each expression can be
constructed from one or more of the following unary or binary
expressions:

-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 has its setgid bit set.

-h FILE
     true if FILE exists and is a symbolic link.

-k FILE
     true if FILE exists and has its sticky bit set.

-n STRING
     true if length of STRING is non-zero.

-o OPTION
     true if option named OPTION is on.  OPTION may be a single
     character, in which case it is a single letter option name.  (See
     Note: Specifying Options.)

-p FILE
     true if FILE exists and is a FIFO special file (named pipe).

-r FILE
     true if FILE exists and is readable by current process.

-s FILE
     true if FILE exists and has size greater than zero.

-t FD
     true if file descriptor number FD is open and associated with a
     terminal device.  (note: FD is not optional)

-u FILE
     true if FILE exists and has its setuid bit set.

-w FILE
     true if FILE exists and is writable by current process.

-x FILE
     true if FILE exists and is executable by current process.  If FILE
     exists and is a directory, then the current process has permission
     to search in the directory.

-z STRING
     true if length of STRING is zero.

-L FILE
     true if FILE exists and is a symbolic link.

-O FILE
     true if FILE exists and is owned by the effective user ID of this
     process.

-G FILE
     true if FILE exists and its group matches the effective group ID
     of this process.

-S FILE
     true if FILE exists and is a socket.

-N FILE
     true if FILE exists and its access time is not newer than its
     modification time.

FILE1 -nt FILE2
     true if FILE1 exists and is newer than FILE2.

FILE1 -ot FILE2
     true if FILE1 exists and is older than FILE2.

FILE1 -ef FILE2
     true if FILE1 and FILE2 exist and refer to the same file.

STRING = PATTERN
STRING == PATTERN
     true if STRING matches PATTERN.  The `==' form is the preferred
     one.  The `=' form is for backward compatibility and should be
     considered obsolete.

STRING != PATTERN
     true if STRING does not match PATTERN.

STRING1 < STRING2
     true if STRING1 comes before STRING2 based on ASCII value of their
     characters.

STRING1 > STRING2
     true if STRING1 comes after STRING2 based on ASCII value of their
     characters.

EXP1 -eq EXP2
     true if EXP1 is numerically equal to EXP2.

EXP1 -ne EXP2
     true if EXP1 is numerically not equal to EXP2.

EXP1 -lt EXP2
     true if EXP1 is numerically less than EXP2.

EXP1 -gt EXP2
     true if EXP1 is numerically greater than EXP2.

EXP1 -le EXP2
     true if EXP1 is numerically less than or equal to EXP2.

EXP1 -ge EXP2
     true if EXP1 is numerically greater than or equal to EXP2.

( EXP )
     true if EXP is true.

! EXP
     true if EXP is false.

EXP1 && EXP2
     true if EXP1 and EXP2 are both true.

EXP1 || EXP2
     true if either EXP1 or EXP2 is true.

Normal shell expansion is performed on the FILE, STRING and PATTERN
arguments, but the result of each expansion is constrained to be a
single word, similar to the effect of double quotes.  However, pattern
metacharacters are active for the PATTERN arguments; the patterns are
the same as those used for filename generation, see Note: Filename
Generation, but there is no special behaviour of `/' nor initial
dots, and no glob qualifiers are allowed.

In each of the above expressions, if FILE is of the form `/dev/fd/N',
where N is an integer, then the test applied to the open file whose
descriptor number is N, even if the underlying system does not support
the /dev/fd directory.

In the forms which do numeric comparison, the expressions EXP undergo
arithmetic expansion as if they were enclosed in $((...)).

For example, the following:

     [[ ( -f foo || -f bar ) && $report = y* ]] && print File exists.

tests if either file foo or file bar exists, and if so, if the value of
the parameter report begins with `y'; if the complete condition is
true, the message `File exists.' is printed.


automatically generated by info2www version 1.2.2.9