Last Updated: February 25, 2016
·
296
· victorbrca

Bash Parameter Substitution: Deleting characters from a variable value

Here's how to use Bash's parameter substitution to delete all spaces in a variable:

$ VAR="This is a var"
$ echo ${VAR// /}
Thisisavar

You can also use it to delete a character

$ echo ${VAR//a/}
This is vr

A word

$ echo ${VAR//This/}
is a var

Or a pattern

$ VAR="This is a var 123"
$ echo ${VAR//[a-z]/}
123

Note that when using [a-z] it does not respect case