/bin/sh shell script that will
help you processing form data in a CGI shell script, without needing
C or perl. You receive the form values straight into your
shell environment, where you can then access them just like other
shell variables. About no special requirements are needed, it just uses
the standard Unix utilities dd, test, grep, cut,
dc and echo. The latter must be able to print arbitrary
Note: Writing this script was interesting, but the program is also kind of a joke. I wanted to prove that it is indeed possible to pick apart CGI data with a shell script, and I succeeded. Yet the script has some deficiencies.Now back to the shell script ...
Don't get me wrong. Programming CGI shell scripts isn't a bad idea in general, it indeed works quite well for small jobs. But evaluating the form data shouldn't be done in a script.
One problem is that this script is slow. For biting its way through the data string, it must continuously invoke the afore-mentioned utilities. Hundreds of times. Second, there are a few tiny differences in the tools' implementations on various platforms, so in rare cases, obscure problems may occur.
I never expected the overwhelming feedback on my script. Unfortunately, it didn't always work out perfectly. It is much better having an integrated piece of C code that does the job than a shell script. I have decided to write such a tool, proccgi, to help all folks that were having problems getting the script to work. Unless you know what you're doing, or are looking for fascinating shell scripts, please use that program to evaluate form data in your shell CGI scripts instead, it's much easier to use.
If you are currently using the script on your site, you can simply switch over to proccgi. It works the same, and you only need to change a single line of code in your CGI scripts.
A big thank you to all who have used this shell script in the past, present, and future, and to those who commented on it.
Yet another option is to switch to the Tcl language for CGI scripting. It's powerful and easy to use; I use it for most of my scripting these days. Of course I also have a Tcl script for CGI data evaluation: proccgi.tcl.
/A=trash), it is processed as well.
eval `proccgi.sh $*`In some cases, you might need to give the full pathname if it's not found automatically. After this call, you have everything in your shell.
If something goes wrong, you can also enable some debugging output by setting the variable DEBUG to 1, causing a log to be printed to standard error. To get a debugging logfile, you would call
DEBUG=1 export DEBUG eval `proccgi.sh $* 2> logfile`
<form action="http://our-server/cgi-stuff/mailer" method="post"> <dl> <dt> Your Email <dd> <input name="email" size="50"> <dt> Filename <dd> <input name="file" size="50"> </dl> <input type="submit" value="Submit"> </form>
#!/bin/sh eval `proccgi.sh $*` mail $FORM_email < $FORM_file cat - << \END echo Content-type: text/plain echo echo done. ENDAs you can see, after the call to
email address from the form is stored in the shell variable $FORM_email,
and the file name is in $FORM_file.
The script may be freely used and distributed at no charge provided that the copyright notice remains at its top.