In bash programming, given a variable, say varA, that store a string containing # symbol. Let's assume varA contain this value: ASD# 1, I need to append a backslash \ at the front of #, so the output could have this: ASD\# 1. The following code is about there to achieve my objective, just that the string replacement doesn't seem to work and I'm not able to assign the output from sed command into another variable. Any sight on this?varA=ASD# 1echo $(sed s/\#/\\#/g <<< ${varA})
how to insert backslash at the front of # symbol?
shell script;sed;quoting
You missing quote in your sed expression.Try:$ varA=ASD# 1$ echo $(sed 's/#/\\#/g' <<< ${varA})ASD\# 1