60 lines
2.6 KiB
Plaintext
60 lines
2.6 KiB
Plaintext
|
|
# CONDITIONAL EXPRESSIONS
|
|
|
|
## File Conditionals
|
|
|
|
| Expression | Value | What does it do? |
|
|
| ---------- | ------ | ---------------- |
|
|
| `-a` | `file` | If file exists.
|
|
| `-b` | `file` | If file exists and is a block special file.
|
|
| `-c` | `file` | If file exists and is a character special file.
|
|
| `-d` | `file` | If file exists and is a directory.
|
|
| `-e` | `file` | If file exists.
|
|
| `-f` | `file` | If file exists and is a regular file.
|
|
| `-g` | `file` | If file exists and its set-group-id bit is set.
|
|
| `-h` | `file` | If file exists and is a symbolic link.
|
|
| `-k` | `file` | If file exists and its sticky-bit is set
|
|
| `-p` | `file` | If file exists and is a named pipe (*FIFO*).
|
|
| `-r` | `file` | If file exists and is readable.
|
|
| `-s` | `file` | If file exists and its size is greater than zero.
|
|
| `-t` | `fd` | If file descriptor is open and refers to a terminal.
|
|
| `-u` | `file` | If file exists and its set-user-id bit is set.
|
|
| `-w` | `file` | If file exists and is writable.
|
|
| `-x` | `file` | If file exists and is executable.
|
|
| `-G` | `file` | If file exists and is owned by the effective group ID.
|
|
| `-L` | `file` | If file exists and is a symbolic link.
|
|
| `-N` | `file` | If file exists and has been modified since last read.
|
|
| `-O` | `file` | If file exists and is owned by the effective user ID.
|
|
| `-S` | `file` | If file exists and is a socket.
|
|
|
|
## File Comparisons
|
|
|
|
| Expression | What does it do? |
|
|
| ---------- | ---------------- |
|
|
| `file -ef file2` | If both files refer to the same inode and device numbers.
|
|
| `file -nt file2` | If `file` is newer than `file2` (*uses modification time*) or `file` exists and `file2` does not.
|
|
| `file -ot file2` | If `file` is older than `file2` (*uses modification time*) or `file2` exists and `file` does not.
|
|
|
|
## Variable Conditionals
|
|
|
|
| Expression | Value | What does it do? |
|
|
| ---------- | ----- | ---------------- |
|
|
| `-o` | `opt` | If shell option is enabled.
|
|
| `-v` | `var` | If variable has a value assigned.
|
|
| `-R` | `var` | If variable is a name reference.
|
|
| `-z` | `var` | If the length of string is zero.
|
|
| `-n` | `var` | If the length of string is non-zero.
|
|
|
|
## Variable Comparisons
|
|
|
|
| Expression | What does it do? |
|
|
| ---------- | ---------------- |
|
|
| `var = var2` | Equal to.
|
|
| `var == var2` | Equal to (*synonym for `=`*).
|
|
| `var != var2` | Not equal to.
|
|
| `var < var2` | Less than (*in ASCII alphabetical order.*)
|
|
| `var > var2` | Greater than (*in ASCII alphabetical order.*)
|
|
|
|
<!-- CHAPTER END -->
|
|
|