- Forums
- Linux
- How To Escape $ Dollar Sign In Linux Commands And Scripts
I Will Show You How You Can Escape The Dollar Sign $ In A Linux Shell Command [3285], Last Updated: Sun Jul 05, 2020
Webune Support
Tue Feb 02, 2010
2 Comments
2061 Visits
we provide linux dedicated servers - to help our customer who program in linux you might find this trick helpful
do you have a command that you use the dollar sign ($) and you want to display the actual $ dollar sign instead of the variable value, lets say for example you have this command where you want to find and replace values in a file
this is how our expenses.txt file looks like:
expenses.txt
Marry Jones: $455.22
Joe Smith: $255.00
John Maks: $655.55
ok, lets say we want to replace the value of Marry's salary from $455.22 to $500.00 we can use this command:
awk '{gsub(/\$455.22/, "$500.00", $0); print > FILENAME}' expenses.txt
that will change to:
expenses.txt
Marry Jones: $500.00
Joe Smith: $255.00
John Maks: $655.55
hope that helps
so basically if you want to escape the $ character in unix, just add the \ slash before or you might get a message the looks like this:
awk: warning: escape sequence `\$' treated as plain `$'