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
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
Here you can use both html and UNIX commands