0

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
0

1 Answer 1

1
cat <<'EOF' >>"$name"
Data...
EOF
10
  • thanks that worked, can i also make an if structure for putting some part of text in there? Dec 28, 2017 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. Dec 28, 2017 at 9:43
  • U mean in the file? for example cat <<'EOF' >>$name $(if (($read == yes)))... EOF Dec 28, 2017 at 9:47
  • yeah, don't do it that way. Do if ...; then echo "foo" >> $name; fi; cat << EOF ... Dec 28, 2017 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, 2017 at 10:04

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