b85hqa
Last Updated: February 25, 2016
·
155
· victorbrca
409302 10151131950910230 214813917 n 2

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

Say Thanks
Respond
Filed Under