Unix dollar sign exit inside cat command

In Ubuntu, I would like to get a file on disk that says:

foo $(bar) 

I would like to create this file using the cat , for example

 cat <<EOF > baz.txt type_magic_incantation_here_that_will_produce_foo_$(bar) EOF 

The problem is the dollar sign. I have tried several combinations of backslash, single quote, and double quote characters and cannot make it work.

+6
source share
2 answers

You can use regular citation operators in a document:

 $ cat <<HERE > foo \$(bar) > HERE foo $(bar) 

or you can disable the extension by specifying the here-doc delimiter:

 $ cat <<'HERE' # note single quotes > foo $(bar) > HERE foo $(bar) 
+12
source

The backslash ('\') works for me. I tried this and here is the conclusion:

 $ cat <<EOF > tmp.txt foo \$(abc) EOF $ cat tmp.txt foo $(abc) 

I tried it on bash. I am not sure whether to use a different escape character in a different shell.

+1
source

All Articles