Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script variable replacing characters

I have a variable var="abcde$$$$$$$$fff$$gg". I want to replace all $ with space ' ' but the following puts just one space

var=$( echo "$var" | tr '$' ' ')

How can i replace them all?

like image 426
thetux4 Avatar asked Apr 29 '11 14:04

thetux4


1 Answers

you can replace without calling external commands (using bash)

$ var='abcde$$$$$$$$fff$$gg'
$ echo "${var//$/ }"
abcde        fff  gg

Note that you should use single quotes so that the "$" sign does not get interpolated

like image 126
ghostdog74 Avatar answered Oct 08 '22 04:10

ghostdog74