-1

This is silly, and I've tried searching for a way to do this, and many sites instruct to do the same thing, but nothing works.

#!/bin/bash
message_content="$(cat <<-EOF
    A
        B
    C
EOF
)"

echo $message_content > test

Expected output of cat test :

A
B
C

Actual output of cat test :

A B C

What's going on?

1 Answers1

3

Does this not work for you?:

#!/bin/bash
cat <<EOF > test
A
B
C
EOF

or you can do:

#!/bin/bash
message_content="$(cat <<-EOF
    A
        B
    C
EOF
)"

echo "$message_content" > test

as the previous comment suggested. e.g. quote the variable

Ron
  • 235
  • Yes, but is there a way to put the content in a variable instead of directly send it into the file? The file is just a test to see if the output indeed contains multiple lines. – Yanick Rochon Aug 25 '20 at 01:33