Remove spaces in string in bash variable

There are multiple way to remove spaces,

# Variable a contains the following
a="Hello World !"

echo

echo ${a// /}

Sed

echo $a | sed "s/\ //g"

tr

tr -d ' ' <<<"$a"

or

echo $a | tr -d ' ' 

Returned output

HelloWorld!

Leave a Reply

Your email address will not be published. Required fields are marked *