Unix CGI Scripts

by Philip Greenspun for the Web Tools Review

CGI stands for Common Gateway Interface. It is an abstraction barrier between the server program on your Unix box and any scripts that you may write. This lets you run the same script with NCSA HTTPD or Netcape's Commerce Server or the CERN server or whatever.

You should probably read some of the interface documentation before writing any of your own scripts, but the ten-second explanation is the following:

Example in Perl

Perl is one of the nastiest computer languages yet developed but it is universal and very popular for writing CGI scripts. If you ask around on USENET or surf the Web, you will probably be able to find a perl script that does almost what you want and then modify it.


# the first line in a Unix shell script says where to find the
# interpreter.  If you don't know where perl lives on your system, type
# "which perl" at any shell and put that after the #!

print "Content-type: text/html\n\n";

# now we have printed a header (plus two newlines) indicating that the
# document will be HTML so whatever else we write to standard output will 
# show up on the page

print "<h3>Hello World</h3>";

More Perl examples

Return to Web Tools Review home


Add a comment | Add a link