这里文档符号
Here document notations
我在此处的文档中找不到关于符号的太多解释。在我的 shell 脚本中,我正在使用 gnuplot 绘制一个文件。
此代码有效:
gnuplot <<- EOF
set xlabel "square dimension (inches)"
set ylabel "mean survival time (seconds)"
set term png
set output "${plot_file}.png"
plot "beetle.dat" using 1:2
EOF
但是,如果我不在 <<-
中包含破折号而只使用 <<
,则此代码不起作用并且我收到以下错误:
./myscript: line 118: warning: here-document at line 104 delimited by end-of-file (wanted `EOF')
./myscript: line 119: syntax error: unexpected end of file
这个问题之前可能有人问过,但是由于无法识别特殊字符,我无法搜索。
当你说 "this code" 时,是代码 - 还是缩进?
Heredocs 默认查找仅包含定界符的行,因此没有前导制表符或空格。 “-”的作用是删除前导制表符,因此您可以缩进 heredoc(包括内容和定界符),与代码的其余部分保持一致。
所以如果你的分隔符实际上在代码中缩进了,它只会与“-”一起找到
见https://www.gnu.org/software/bash/manual/html_node/Redirections.html
中的3.6.6
我在此处的文档中找不到关于符号的太多解释。在我的 shell 脚本中,我正在使用 gnuplot 绘制一个文件。
此代码有效:
gnuplot <<- EOF
set xlabel "square dimension (inches)"
set ylabel "mean survival time (seconds)"
set term png
set output "${plot_file}.png"
plot "beetle.dat" using 1:2
EOF
但是,如果我不在 <<-
中包含破折号而只使用 <<
,则此代码不起作用并且我收到以下错误:
./myscript: line 118: warning: here-document at line 104 delimited by end-of-file (wanted `EOF')
./myscript: line 119: syntax error: unexpected end of file
这个问题之前可能有人问过,但是由于无法识别特殊字符,我无法搜索。
当你说 "this code" 时,是代码 - 还是缩进?
Heredocs 默认查找仅包含定界符的行,因此没有前导制表符或空格。 “-”的作用是删除前导制表符,因此您可以缩进 heredoc(包括内容和定界符),与代码的其余部分保持一致。
所以如果你的分隔符实际上在代码中缩进了,它只会与“-”一起找到
见https://www.gnu.org/software/bash/manual/html_node/Redirections.html
中的3.6.6