bashapachecgi-bin

cgi-bin, bash and formatting output


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

Solution

  • 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