"Here Documents" 的更清晰替代方案

Clearer alternative to "Here Documents"

在 bash 脚本中创建文件 example 时,您可以使用 cathere document 并以 EOF 作为分隔符:

cat <<EOF > example
1234
ABCD
EFGH
EOF

对于 bash 新手来说这看起来很复杂,所以是否有更清晰的版本来编写这段代码?

来自男人 bash:

If the redirection operator is <<-, then all leading TAB characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.

所以这看起来更干净了:

cat <<-EOF > example
    1234
    ABCD
    EFGH
EOF

每行前的空格是制表符!