Variable substitution is typically used to pass the value of a variable as an argument to a command. For example: echo $message
The ${...} variations are used to isolate the variable substitution from whatever text (including any colons) may follow.
| Reference | Meaning |
|---|---|
| $var |
Value of variable var |
| ${var} |
Same as $var except separated from anything following. |
| $var[ expr ] |
Value of var, indexed by an arbitrarily complex expression. |
| ${var[ expr ]} |
Same as $var[expr] except separated from anything following. |
| $#var |
Number of words in var. |
| ${#var} |
Same as $#var except isolated from anything following. |
| $?var |
1 if var exists; 0 otherwise. |
| ${?var} |
Same as $?var except isolated from anything following. |
| $proc( arglist ) |
Procedure reference, used as a variable substitution. The arguments are expressions, separated by commas. Any value returned by the procedure will be substituted in place. |
| $< |
Pseudo-variable result of reading one line from stdin each time it’s evaluated. Same as $getline. |
| $* |
Same as $argv |
| $0 through $9 |
Same as $argv[0] through $argv[9] |
Substitution modifiers
Expression operators
@, calc, set, setenv and local
Predefined environment variables
Predefined shared variables
Predefined inherited variables
Predefined initialized variables
Combined list of predefined variables
Tutorial: Variables
Tutorial: Editing