[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cgi and bash



On Thu, Sep 07, 2017 at 01:46:50PM +0200, Pol Hallen wrote:
Hello all

I try to formatting out put cat command

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

thanks for help! :)

#!/bin/bash
echo "Content-type: text/html"
echo
echo "<html><head><title>Contents of file /tmp/file</title></head><body>"

cat /tmp/file | while read line ; do
  echo "<p><tt>$line</tt></p>"
done

echo "</body></html>"

So, what I'm doing there is printing the content-type, then the body (you'll have to check that that's proper CGI as it's been ages since I did any of that), then printing a bare-bones HTML file. Note that certain tags are required to make a valid HTML document. Just printing content and claiming it's HTML is *not* valid. What I've done is "cat /tmp/file | while read line ..." which will loop over the lines in /tmp/file and, for each one, assign the contents to $line. I then use that variable as the content in a paragraph (<p/>). I've also marked up the text as "teletype" text which usually means it gets printed in a monospace font. YBMV.

For more information, the CGI specification is RFC 3875 and the HTML specification is https://www.w3.org/TR/html/



Pol


--
For more information, please reread.

Attachment: signature.asc
Description: PGP signature


Reply to: