Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Escape special characters in shell scripting

Status
Not open for further replies.

tulsantide

Technical User
Jun 1, 2015
21
US
Hi,

How to escape special characters in a shell script? Following is working for all the special characters below except for $ and (). Please let me know the solution.

echo "@abc!=${bca}:/{^t&e-st*#}"|sed 's/[$!@{#%}^&*()/-]/\\&/g'
\@abc\!=:\/\{\^t\&e\-st\*\#\}


Thanks
 
I'm not sure what you're trying to do.

The ${bca} is being replaced by the shell because it's in double quotes, so you're telling the shell it's ok to replace that. If it was in single quotes, the shell would leave it alone.

Code:
echo [b][COLOR=#EF2929]'[/color][/b]@abc!=${bca}:/{^t&e-st*#}[b][COLOR=#EF2929]'[/color][/b] | sed 's/[$!@{#%}^&*()/-]/\\&/g'
\@abc\!=[b][COLOR=#EF2929]\$\{bca\}[/color][/b]:\/\{\^t\&e\-st\*\#\}

Not sure where the () issue comes in.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top