parameter expansion
Replacing a dollar sign and a variable name with the variable's value, optionally transformed by an operator inside curly braces.
In more detail
Plain $name is the simplest form; ${name} marks where the name ends. Operators inside the braces supply defaults, lengths, slices, trimming, replacement and case changes without starting any other program. The result is still subject to word splitting and globbing unless the expansion is in double quotes.
Example
echo "${name}_backup"Related terms
- default value expansion — The ${name:-fallback} form, which gives the fallback when the variable is unset or empty, without changing the variable.
- string length expansion — The ${#name} form, which expands to the number of characters in a variable, or ${#array[@]} for the number of elements.
- substring expansion — The ${name:offset:length} form, which takes part of a string starting at a zero-based offset.
- prefix and suffix removal — The ${name#pattern} and ${name%pattern} forms, which remove a matching glob pattern from the start or the end of a value.
- pattern substitution — The ${name/pattern/replacement} form, which replaces the first match of a glob pattern in a value, or every match with a double slash.
- case modification — The ${name^^} and ${name,,} forms, which convert a value to upper or lower case; a single caret or comma changes only the first letter.
Taught in
- What Bash Does To A Line Before It Runs It — Bash Scripting & Command Line Automation
- Parameter Expansion: Defaults, Length, Slices — Bash Scripting & Command Line Automation
- Trimming, Replacing And Changing Case — Bash Scripting & Command Line Automation
- eval, And What To Use Instead — Bash Scripting & Command Line Automation