【发布时间】:2016-04-04 20:12:57
【问题描述】:
我正在尝试使用带有以下 sn-p 的 here-script 将一些 html 文本打印到 html 文档中。 $file 是 sometext.html,每当我运行它时,我都会得到一个错误:
line 126: warning: here-document at line 107 delimited by end-of-file (wanted _EOF_)
#!/bin/bash
echo << _EOF_
<html>
<head>
<title>
$TITLE $HOSTNAME
</title>
</head>
<body>
<h1>$TITLE</h1>
<p>$pTIME_STAMP</p>
$(system_info) <br>
$(show_uptime) <br>
$(drive_space) <br>
$(home_space) <br>
</body>
</html>
_EOF_
exit 0
编辑:我主要是从How can I write a here doc to a file in Bash script?复制答案
【问题讨论】:
-
您是不是要使用
cat而不是echo? -
是的,我最初使用的是 cat 然后尝试了 echo 只是因为,我会改回来。
-
嗯...切换到
cat后,这对我很有用。周围的脚本中是否还有其他事情发生?文档的内容(“html 内容”)有什么奇怪的地方吗? -
脚本的第 107 行是什么?
-
确保您在该行之后
_EOF_也没有空格。见stackoverflow.com/questions/12503581/…