【问题标题】:redirecting here-document, delimited by end-of-file [duplicate]重定向此处的文档,由文件结尾分隔 [重复]
【发布时间】: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/…

标签: bash shell


【解决方案1】:

确保在最后一个_EOF_之前没有空格

【讨论】:

    猜你喜欢
    • 2015-01-27
    • 2018-05-09
    • 2013-08-08
    • 2019-08-13
    • 2012-05-28
    • 2017-08-11
    • 2012-09-12
    • 2016-06-01
    • 2017-05-18
    相关资源
    最近更新 更多