Definition
Parameter expansion is the family of bash syntax forms that substitute the value of a variable into a command line, optionally transforming the value as it is substituted. The basic form is the variable name wrapped in dollar-sign braces; richer forms add operators inside the braces to set defaults, slice substrings, strip prefixes or suffixes, change case, replace patterns, and report length. Together these operators form a compact string-processing sublanguage that runs entirely inside the shell, with no fork to sed, awk, or cut.
The braces are what make expansion distinct from a bare dollar-sign reference. A bare reference inserts the value; a braced form can also transform it. Many scripts that look like they need a chain of external tools can be replaced with a single braced expansion.
Why it matters
How it works
The operator alphabet is small but expressive. Default-value forms like ${VAR:-fallback} use the fallback when VAR is unset or empty, and ${VAR:=fallback} also assigns the fallback to VAR for subsequent use. Length is ${#VAR}. Substring extraction is ${VAR:offset:length}, with negative offsets counting from the end. Prefix stripping is ${VAR#pattern} (shortest match) or ${VAR##pattern} (longest); suffix stripping uses % and %% the same way. Pattern replacement is ${VAR/pattern/replacement} (first match) or ${VAR//pattern/replacement} (all matches). Case conversion uses ^^ and ,, for upper and lower.
The patterns these operators accept are glob patterns, not regular expressions. Asterisk matches any number of characters, question mark matches one, and bracket expressions list character classes. This is the same dialect that file-name expansion uses, which makes the shell internally consistent but trips up users who expect ECMAScript or PCRE syntax inside braces. For full regular expressions, the shell offers a separate construct — the [[ string =~ regex ]] test inside conditional expressions — which is regex-based but does not support replacement.