Usually I do my server-side scripting in Perl, but some time
ago when writing CGI scripts for an embedded system I ran into memory
and flash space contraints. Because the system used Busybox, I
had the Bourne compatible ash shell available.
So I wrote a very small Bourne shell script to include in my CGI scripts,
which I share here, maybe it is of use to someone.
(Of course this will work in the Bash shell as well.)
This code is probably one big security hole waiting to happen,
interactive shells and the Internet don’t mix very well, please
use wisely. :)
This is the script to be included from each individual CGI:
This code can be then be used in your CGI scripts like so, for example
this little script, that simply displays all posted variables.
All posted variables, together with those in the query string in
the URL are prefixed with F_ which makes this small example very
echo POSTed or GETted variables:
set | grep -e '^F_'
This example uses the following form to provide input:
<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="en"><head></head><body><formmethod="POST"action="cgi-bin/test.cgi?get_var=blah"><inputtype="text"name="field1"><br><inputtype="text"name="field2"><br><inputtype="text"name="field3"><br><inputtype="submit"></form></body></html>
All the code on this page is available in a tarball here: cgi.tar.gz