0

This question already has an answer here:

This command doesn't seem to work in my script, how can I decide in which file I want this text, if I just create a file with the following command

touch $name

I want the text to be in the file $name that I just made in my script.

cat <<'EOF'
Data...
EOF

marked as duplicate by αғsнιη, Archemar, George Vasiliou, Bernhard, jimmij Dec 28 '17 at 13:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
cat <<'EOF' >>"$name"
Data...
EOF
  • thanks that worked, can i also make an if structure for putting some part of text in there? – florian de wulf Dec 28 '17 at 9:41
  • you could, by using $( do something here ), but I wouldn't. It gets indeciphrable/messy/incomprehensible quickly. Do the comparisons outside of the here document part and insert text there via variables for example or maybe better: compose the text bit by bit. – Tomáš Pospíšek Dec 28 '17 at 9:43
  • U mean in the file? for example cat <<'EOF' >>$name $(if (($read == yes)))... EOF – florian de wulf Dec 28 '17 at 9:47
  • yeah, don't do it that way. Do if ...; then echo "foo" >> $name; fi; cat << EOF ... – Tomáš Pospíšek Dec 28 '17 at 9:48
  • 1
    $name needs to be quoted. e.g. "$name". See unix.stackexchange.com/a/65633/7696 for a good summary of why variables should (almost) always be quoted. – cas Dec 28 '17 at 10:04

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