I have been using the pattern below for printing multiline messages to terminal in a bash script.
read -d '' message <<- EOF
this is a
mulitline
message
EOF
echo "$message"
This has been working - until a couple of days ago the pattern just stopped working. By stopped working, I mean when bash encountered these heredoc expressions in the script - it just seems to do nothing - no output.
The only thing that I can think of thats changed in the last few days is that the environment the scripts are run inside is a Ubuntu 14.04 live USB, versus "full" installs.
Then I discovered that when I move the heredoc before the scripts set -o errexit
statement it started working again. i.e. this doesn't work
#!/bin/bash
set -o errexit
read -d '' message <<- EOF
this is a
mulitline
message
EOF
echo "$message"
result: (nothing)
But this does work
#!/bin/bash
read -d '' message <<- EOF
this is a
mulitline
message
EOF
echo "$message"
result
$ sudo ./script.sh
this is a
mulitline
message
- bash --version -
GNU bash, version 4.3.11(1)-release (i686-pc-linux-gnu)