6

I'm trying to preserve $if below and
would like the following to output
$if

bash is getting in the way by doing
$ substitution

$ sed -e 's:\\$:\\$:g' <<ENDOFFILE  
> $if  
> ENDOFFILE  

or

$ tr '$' '\$' <<ENDOFFILE  
> $if  
> ENDOFFILE  

Is there a way to preserve $keywords
to stdout without explicitly escaping
them out in stdin?

Should I switch to another shell before attempting this?

2 Answers2

8

I'm not sure what you are trying to do but bash is performing parameter expansion in your here document because the delimiter ENDOFFILE. If you were to change it to 'ENDOFFILE' bash would not expand.

Mark Wagner
  • 17,764
  • 2
  • 30
  • 47
0

Not sure what exactly you are trying to do here, but you can use tr and the octal value of $ which is 044. Experiment with this:

echo 'ab$de' | tr \\044 C

jftuga
  • 5,572
  • 4
  • 39
  • 50
  • Test your recommendation. He's trying to escape a variable via STDIN using string manipulation. You are escaping in the echo. – Warner Aug 03 '10 at 19:52