This is one way to assign the contents of a here document to a variable. However, its execution will return a status of 1 without stating a reason.
#! /bin/bash
# set -e -x
# This implementation returns 1
define(){ IFS='\n'; read -r -d '' ${1}; }
define thedoc <<'EOF'
Here is my here doc.
There was an ASCII banana here too,
but `read` would just it concatenate to mush.
EOF
# The here document will print with the following when `set -e` in not invoked.
echo $thedoc
Everything checks out by inspection and even execution provided that set -e is turned off. This is not exclusive to the Banana above but any here doc built by define() above. From where does that error arise?
thedoc.