Testing CGI manually
Need to work out why the 'code' and 'pre' blocks are not working ... and using pre direct is also playing up.
Mistral threw out a short test script as part of it's process to establish why cgi was not working. I added the !DOCTYPE line to keep Firefox happy but I'm not quite sure at the moment why I need the blank line before it? The script that appears in the browser starts with the !DOCTYPE line so is functional.
#!/bin/bash echo "Content-Type: text/html" echo "" echo "<!DOCTYPE html>" echo "<html>" echo "<head><title>CGI Test</title></head>" echo "<body>" echo "<h1>CGI Script Works!</h1>" echo "</body>" echo "</html>"
This is an area I probably need to investigate further. I presume that I could run python scripts from here if they produce html pages. Checking back with Mistral gave some tidy notes on the basics, including why the blank line is necessary!
Updated Script Breakdown:
-
Shebang (
#!/bin/bash
):- Indicates that the script should be run using the Bash shell.
-
Content-Type Header:
echo "Content-Type: text/html"
: Sends the HTTP headerContent-Type: text/html
to the web server.
-
Blank Line:
echo ""
: Separates the HTTP headers from the body of the response.
-
DOCTYPE Declaration:
echo ""
: Declares the document type as HTML5.
-
HTML Content:
- The rest of the script generates the HTML content.
echo "
: Starts the HTML document.echo "
: Starts the head section of the HTML document.echo "
"
: Sets the title of the HTML document.echo ""
: Ends the head section.echo "
: Starts the body section of the HTML document.echo " Hello, World!
"
: Adds a level 1 heading with the text "Hello, World!".echo ""
: Ends the body section.echo ""
: Ends the HTML document.
A good starting point ...