How to remove space from string?

bash, shell

Solution

Try doing this in a shell:

var="  3918912k"
echo ${var//[[:blank:]]/}

That uses parameter expansion (it's a non posix feature)

`[[:blank:]]` is a POSIX regex class (remove spaces, tabs...), see http://www.regular-expressions.info/posixbrackets.html

Problem

In ubuntu bash script how to remove space from one variable string will be ``` 3918912k ``` Want to remove all blank space.

Original source

Related problems