Escaping a dollar sign in Unix inside the cat command

On Ubuntu, I would like to end up with a disk file that reads:

foo $(bar)

I would like to create this file using the cat command, e.g.

cat <<EOF > baz.txt

The problem is the dollar sign. I have tried multiple combinations of backslash, single-quote, and double-quote characters, and cannot get it to work.


You can use regular quoting operators in a here document:

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

or you can disable expansion in the entire here document by quoting or escaping the here-doc delimiter:

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

It doesn't matter whether you use single or double quotes or a backslash escape (<<\HERE); they all have the same effect.

Backslash ('\') works for me. I tried it and here is the output:

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

$ cat tmp.txt 
foo $(abc)

I tried it on bash. I'm not sure whether you have to use a different escape character in a different shell.

Need Your Help

How to fix: W602 deprecated form of raising exception

python pylint pep8

If I use pylint (via sublimerlinter) I get following warning message:

NodeJS UDP Multicast How to

node.js udp multicast

I'm trying to send a UDP Multicast Packet to: so everyone subscribed will receive. A bit stuck. I believe it's broadcasting correctly, but can't seem to pick anything up with any cl...