【问题标题】:cgi-bin, bash and formatting outputcgi-bin、bash 和格式化输出
【发布时间】:2018-02-16 01:45:01
【问题描述】:

cat /usr/lib/cgi-bin/test00.cgi

#!/bin/bash
echo "Content-type: text/html"
cat /tmp/file

结果是:

one two three four

如何像 bash 脚本一样格式化输出(带换行符)?

one
two
three
four

【问题讨论】:

  • 你试过text/plain而不是text/html吗?
  • one two three four 是从哪里打印出来的? echo 字符串在哪里 Content-type: text/html
  • @Inian OP 正在编写 CGI 脚本。所以我假设 OP 指的是 网络浏览器 呈现结果 HTTP 响应的方式。 Context-type 是 HTTP 标头的一部分,因此不直接可见。剩下的显然是/tmp/file的内容。

标签: bash apache cgi-bin


【解决方案1】:

在这里您可以同时使用 html 和 UNIX 命令

#!/bin/bash

echo Content-type: text/html
echo ""

/bin/cat << EOM
<HTML>
<HEAD><TITLE>File Output: /tmp/file </TITLE>
</HEAD>
<BODY bgcolor="#cccccc" text="#000000">
<HR SIZE=5>
<H1>File Output: /tmp/file </H1>
<HR SIZE=5>
<P>
<SMALL>
<PRE>
EOM

/bin/cat /tmp/file

CAT << EOM
</PRE>
</SMALL>
<P>
</BODY>
</HTML>
EOM

【讨论】:

    猜你喜欢
    • 2011-05-03
    • 2014-06-07
    • 2015-04-03
    • 2014-04-08
    • 2011-08-03
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多