| Previous | Table of Contents | Next |
THIS CHAPTER CONTAINS TABLES OF SYNTAX ELEMENTS FOR ALL THREE SHELLS AND examples of shell scripts.
| Feature | Bourne | Korn | C |
|---|---|---|---|
| Read at login | .profile | .profile | .login |
| Read at invocation of shell | Any file specified in .profile with ENV=.file | .cshrc |
| Shell | Syntax |
|---|---|
| Bourne | #!/bin/sh |
| Korn | #!/bin/ksh |
| C | #!/bin/csh -f |
| Operator | Description |
|---|---|
| ${variable# pattern} | Delete the shortest part at the beginning of the variable that matches the pattern and return the rest. |
| ${variable## pattern} | Delete the longest part at the beginning of the variable that matches the pattern and return the rest. |
| ${variable% pattern} | Delete the shortest part at the end of the variable that matches the pattern and return the rest. |
| ${variable%% pattern} | Delete the longest part at the end of the variable that matches the pattern and return the rest. |
| Modifier | Meaning | Description |
|---|---|---|
| :e | Extension | Remove prefix ending with a dot. |
| :h | Head | Remove trailing path name component. |
| :r | Root | Remove suffixes beginning with a dot (.). |
| :t | Tail | Remove all leading pathname components. |
| :q | Quote | Force variable to be quoted. Used to quote $argv. |
| :x | Like q, but break into words at each space, tab, or newline. |
| Variable | Explanation |
|---|---|
| $* | Bourne or Korn shell: List the value of all command-line parameters. This variable is useful only in scripts because the login shell has no arguments associated with it. |
| C shell: Not used. Use $argv instead. | |
| $# | Bourne or Korn shell: Return the number of command-line arguments (in decimal). Useful only in scripts. |
| C shell: Count the number of words (in decimal) in a variable array. | |
| $? | Bourne or Korn shell: Return the exit status (in decimal) of the last command executed. Most commands return a zero exit status if they complete successfully; otherwise, a non-zero exit status is returned. This variable is set after each command is executed. |
| C shell: Check to see if a variable of that name has been set. | |
| $$ | All shells: Return the process ID (PID) number of the current shell (in decimal). |
| $! | All shells: Return the process number (in decimal) of the last process run in the background. |
| Previous | Table of Contents | Next |