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
Written by Victor Mendonca
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Related Tags
#bash
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#