Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Remove particular characters from a variable using bash

I want to parse a variable (in my case it's development kit version) to make it dot(.) free. If version='2.3.3', desired output is 233.

I tried as below, but it requires . to be replaced with another character giving me 2_3_3. It would have been fine if tr . '' would have worked.
1 VERSION='2.3.3' 
2 echo "2.3.3" | tr . _
by

1 Answer

Kajalsi45d
There is no need to execute an external program. bash's string manipulation can handle it (also available in ksh93 (where it comes from), zsh and recent versions of mksh, yash and busybox sh (at least)):
$ VERSION='2.3.3'
$ echo "${VERSION//.}"
233

Login / Signup to Answer the Question.