0

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

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

results is:

one two three four

How format output like a bash script (with newline)?

one
two
three
four
3
  • 2
    Have you tried text/plain instead of text/html? Commented Sep 7, 2017 at 10:46
  • From where is one two three four printed? And where is the echo string Content-type: text/html Commented Sep 7, 2017 at 10:46
  • 1
    @Inian OP is writing a CGI script. So I assume OP refers to the way a web browser is rendering the resulting HTTP response. Context-type is part of the HTTP header and as such not directly visible. The rest is apparently the content of /tmp/file. Commented Sep 7, 2017 at 11:08

2 Answers 2

3

Here you can use both html and UNIX commands

#!/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
Sign up to request clarification or add additional context in comments.

Comments

0

Text in HTML is a subject of https://developer.mozilla.org/en-US/docs/Glossary/Inline-level_content so all white-spaces (including new lines) are replaced with a single (or more depending on alignment) space.

To alter rendering you enclose text into another HTML elements with assigned rendering model:

<div>line 1</div>
<div>line 2</div>

or:

<pre>
line 1
line 2
</pre>

Bash has convenient here-document syntax << to code above:

#!/bin/bash

cat <<EOF
Content-Type: text/html

<pre>
line 1
line 2
</pre>
EOF

Alternatively you could use Content-Type text/plain to preserve original text formatting:

#!/bin/bash

cat <<EOF
Content-Type: text/plain

line 1
line 2
EOF

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.