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
αғsнιη
  • 41,407

1 Answers1

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 09: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 09:43
  • U mean in the file? for example cat <<'EOF' >>$name $(if (($read == yes)))... EOF – florian de wulf Dec 28 '17 at 09:47
  • yeah, don't do it that way. Do if ...; then echo "foo" >> $name; fi; cat << EOF ... – Tomáš Pospíšek Dec 28 '17 at 09:48
  • 1
    $name needs to be quoted. e.g. "$name". See https://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
  • wow thanks that worked, but one more problem this sentence now comes first in my file with the if structure but it should come on the second line after another sentence is this possible? – florian de wulf Dec 28 '17 at 10:16
  • post your code in a new question – Tomáš Pospíšek Dec 28 '17 at 10:18
  • I don't really understand how u mean? – florian de wulf Dec 28 '17 at 10:22
  • oh no i have found it, I made my if structure behind the file, thanks man, but if I put "$name" as text in my file it just prints out "$name" is there another way to print out a name in the file text? – florian de wulf Dec 28 '17 at 10:37
  • You are talking about something that doesn't work as it should however nobody can see that something that doesn't work as you are not showing us. How are we supposed to know what this something that doesn't work is and be able to help you? We are not clairvoyants. – Tomáš Pospíšek Dec 29 '17 at 18:39