这是将此处文档的内容分配给变量的一种方法。但是,它的执行将返回状态 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
如果关闭,一切都通过检查甚至执行来检查。这不是上面的 Banana 独有的,而是define()
上面构建的任何此处的文档。该错误从何而来?