1
这是将here文档的内容分配给变量的一种方法。但是,它的执行将返回状态1,但没有说明原因。通过函数将Heredoc分配给变量的返回状态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()
建立的任何这里的文档。从那里出现错误?
我不确定它是什么意思,但是当我运行你的代码时,所有'n's都被'thedoc'的值中的空格替换。 – chepner
这种行为是预期的。香蕉可能是一个不好的选择。 :P – fny