Hitul Mistry Hitul Mistry - 1 year ago 47
Bash Question

How to remove space from string?

In ubuntu bash script how to remove space from one variable

string will be

3918912k


Want to remove all blank space.

Answer Source

Try doing this in a shell:

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

That uses parameter expansion

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