これは、ヒアドキュメントのコンテンツを変数に割り当てる1つの方法です。ただし、実行すると、理由を指定せずにステータス1が返されます。
#! /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
set -e
オフになっている場合は、検査と実行によってすべてがチェックアウトされます。これは上記のバナナだけではありませんが、上記で作成されたヒアドキュメントdefine()
です。そのエラーはどこから発生しますか?