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.
In more detail
Like trimming it uses glob patterns and runs inside bash, so it is faster than piping the value through sed for simple replacements. The variable itself is unchanged; only the expanded text differs.
Example
echo "${path//\//-}"Related terms
- parameter expansion — Replacing a dollar sign and a variable name with the variable's value, optionally transformed by an operator inside curly braces.
- sed — The stream editor, which applies editing commands such as find-and-replace to each line of text passing through it.
- glob pattern — A pattern that matches names using * for any run of characters, a question mark for one character and [abc] for one of a set.
Taught in
- Trimming, Replacing And Changing Case — Bash Scripting & Command Line Automation