Super User is a question and answer site for computer enthusiasts and power users. 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

I want to do something like this:

$ NAME=John
$ cat << '==end' > test
My name is $NAME

$ cat test
My name is John

Any ideas?

share|improve this question
up vote 12 down vote accepted
cat <<EOF > test
My name is $NAME

or even

cat <<==end > test
My name is $NAME

Worked for me.

Looks like when you take ==end in the ' variable doesn't substitute.

ah, here it is in the man page (look 3.6.6):

The format of here-documents is:


No parameter expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any characters in word are quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion. [...]

share|improve this answer
You can also use double-quotes (cat << "==end" > test), but hard-quotes prevent substitution indeed. – Mat Aug 2 '12 at 7:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .