Here Documents

这种重定向使得 shell 从当前源文件读取输入,直到遇到仅包含 word 的一行 (并且没有尾部空白,trailing blanks) 为止。直到这一点的所有行被用作 命令的标准输入。

here-document 的格式是:

<<[-]word

here-document

delimiter

不会对 word 进行 parameter expansion, command substitution, arithmetic expansion, 或者 pathname expansion。如果 word 中任何字符是引用的, delimiter 将是对 word 进行引用删除的结果,here-document 中的行不会被扩展。如果 word 没有被引用,here-documnet 中的所有行都要经过 parameter expansion, command substitution, 和 arithmetic expansion。 在后一种情况下,字符序列 \<newline> 被忽略;必须用 \ 来引用字符 \, $, 和 `.

如果重定向操作符是 <<-, 那么所有前导的 tab 字符都被从输入行和包含 delimiter 的行中删除。这样使得 shell 脚本中的 here-document 可以被更好地缩进。