The following reference cards provide a useful summary of certain scripting concepts. The foregoing text treats these matters in more depth, as well as giving usage examples.
Table B-1. Special Shell Variables
| Variable | Meaning |
|---|---|
| Filename of script | |
| Positional parameter #1 | |
| Positional parameters #2 - #9 | |
| Positional parameter #10 | |
| Number of positional parameters | |
| All the positional parameters (as a single word) * | |
| All the positional parameters (as separate strings) | |
| Number of command line parameters passed to script | |
| Number of command line parameters passed to script | |
| Return value | |
| Process ID (PID) of script | |
| Flags passed to script (using set) | |
| Last argument of previous command | |
| Process ID (PID) of last job run in background |
* Must be quoted,
otherwise it defaults to
"
Table B-2. TEST Operators: Binary Comparison
| Operator | Meaning | ----- | Operator | Meaning |
|---|---|---|---|---|
| Arithmetic Comparison | String Comparison | |||
| Equal to | Equal to | |||
| Equal to | ||||
| Not equal to | Not equal to | |||
| Less than | Less than (ASCII) * | |||
| Less than or equal to | ||||
| Greater than | Greater than (ASCII) * | |||
| Greater than or equal to | ||||
| String is empty | ||||
| String is not empty | ||||
| Arithmetic Comparison | within double parentheses (( ... )) | |||
| Greater than | ||||
| Greater than or equal to | ||||
| Less than | ||||
| Less than or equal to |
* If within a double-bracket [[ ... ]] test construct, then no escape \ is needed.
Table B-3. TEST Operators: Files
| Operator | Tests Whether | ----- | Operator | Tests Whether |
|---|---|---|---|---|
| File exists | File is not zero size | |||
| File is a regular file | ||||
| File is a directory | File has read permission | |||
| File is a symbolic link | File has write permission | |||
| File is a symbolic link | File has execute permission | |||
| File is a block device | ||||
| File is a character device | sgid flag set | |||
| File is a pipe | suid flag set | |||
| File is a socket | "sticky bit" set | |||
| File is associated with a terminal | ||||
| File modified since it was last read | File F1 is newer than F2 * | |||
| You own the file | File F1 is older than F2 * | |||
| Group id of file same as yours | Files F1 and F2 are hard links to the same file * | |||
| NOT (inverts sense of above tests) |
* Binary operator (requires two operands).
Table B-4. Parameter Substitution and Expansion
| Expression | Meaning |
|---|---|
| Value of | |
| If | |
| If | |
| If | |
| If | |
| If | |
| If | |
| If | |
| If | |
| Matches all previously declared variables beginning with
| |
| Matches all previously declared variables beginning with
|
* Of course if
Table B-5. String Operations
| Expression | Meaning |
|---|---|
| Length of | |
| Extract substring from | |
| Extract | |
| Strip shortest match of
| |
| Strip longest match of
| |
| Strip shortest match of
| |
| Strip longest match of
| |
| Replace first match of
| |
| Replace all matches of
| |
| If | |
| If | |
| Length of matching | |
| Length of matching | |
| Numerical position in | |
| Extract | |
| Extract | |
| Extract | |
| Extract | |
| Extract |
* Where
Table B-6. Miscellaneous Constructs
| Expression | Interpretation |
|---|---|
| Brackets | |
| Test construct | |
| Extended test construct | |
| Array initialization | |
| Range of characters within a Regular Expression | |
| Curly Brackets | |
| Parameter substitution | |
| Indirect variable reference | |
| Block of code | |
| Brace expansion | |
| Extended brace expansion | |
| Text replacement, after find and xargs | |
| Parentheses | |
| Command group executed within a subshell | |
| Array initialization | |
| Command substitution, new style | |
| Process substitution | |
| Process substitution | |
| Double Parentheses | |
| Integer arithmetic | |
| Integer arithmetic, with variable assignment | |
| C-style variable increment | |
| C-style variable decrement | |
| C-style trinary operation | |
| Quoting | |
| "Weak" quoting | |
| 'Strong' quoting | |
| Back Quotes | |
| Command substitution, classic style |