Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If you copy the contents of


and then paste it into a cat command.. such as this one..

cat > /test << EOF
pasted here..

you run into this error:

-bash: command substitution: line 1: unexpected EOF while looking for matching `''
-bash: command substitution: line 4: syntax error: unexpected end of file

perhaps the solution is to escape the dollar signs and maybe even quotes and so on..

but given that this is such a large file.. can dollar signs be automatically be escaped ?

is my only option to escape them via another program and then give it to the cat command ?

share|improve this question
up vote 2 down vote accepted

Compare the two here documents in the following example:

(yeti@darkstar:6)~/wrk/tmp$ cat ./xyzzy 
cat << EOF
Version 1 - Today is $(date)
cat << 'EOF'
Version 2 - Today is $(date)
(yeti@darkstar:6)~/wrk/tmp$ ./xyzzy 
Version 1 - Today is Sa 21. Jun 08:51:38 CEST 2014
Version 2 - Today is $(date)
share|improve this answer

Use quotes around the "EOF" string:

cat > /test <<'EOF'
stuff $(pwd)


stuff $(pwd)


See the bash manual on heredocs. Any quotes in the terminator string prevent any expansions and substitutions in the body.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.