TIL

Bash pattern substitution

Context

I wanted a script to make it quick to generate consistent templates for this repo, so I wanted to take the subject (in this case Bash pattern substitution), and replace the spaces with underscores.

TIL

We can replace underscores in a string with straight up Bash parameter substitution.

variable=${variable// /_}

A generalized form of this would be:

variable=${variable//*PATTERN*/*REPLACEMENT*}

Sources and References

Date

Wednesday, February 19th, 2025
2025-02-19