0

I'm creating a script which create file and insert content using

cat > /etc/file <<END
FILE CONTENT
END

It works for most files but it doesn't work when file content have shell commands in it. I tried with the echo command but i have the same problem.

Why does it execute commands ?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Rck
  • 33
  • 5
  • 2
    Please paste the command that is not working to you – fedorqui Jan 12 '15 at 10:25
  • 2
    If the here-doc contains `$variable`, the variables will be expanded. You need to use `<<'END'` to prevent variables from being expanded. – Barmar Jan 12 '15 at 10:29
  • 1
    Correct ! I had to use backtick escapes to solve my problem, my script contains variables wich were executed. How does i set your answer as valid? Thanks by the way – Rck Jan 12 '15 at 10:41
  • @Barmar maybe you can post this as an answer, as you solved it! – fedorqui Jan 12 '15 at 10:52
  • possible duplicate of [bash tips needed for understanding how to escape characters in command-line](http://stackoverflow.com/questions/2659777/bash-tips-needed-for-understanding-how-to-escape-characters-in-command-line) – tripleee Jan 12 '15 at 11:37

1 Answers1

2

The file's content includes $variables wich are expanded. To avoid variable expansion, I had to use single-quote escapes 'END'.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Rck
  • 33
  • 5