Reputation: 2414
I am using cat to write into file with script shell.
cat <<EOF >/home/test.txt
set $value1 $value2;
EOF
My file containts just this string "set ;" but i need to find "set $value1 $value2;". I guess cat thinks "$value1" is a shell variable but it is just a string that i need to write into a file.
Upvotes: 2
Views: 2138
Reputation: 274542
Use quotes around EOF:
cat <<"EOF" >/home/test.txt
set $value1 $value2;
EOF
From the Here Documents section in man bash
:
The format of here-documents is:
<<[-]word here-document delimiter
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.
Upvotes: 9