Re: [ Mu Tech ] CGI forms parsing WITHOUT perl

From: Mark Roberts (mu@manumark.de)
Date: Wed Aug 09 2000 - 14:20:32 CEST


Dear Bill!

> seeing as mu linux is shell script based, and most of you guys/gals
> would be shell script experts, perhaps you could put together a few lines
> to parse form input web pages in shell script. (I don't want to load the
> Perl module)
>
> ie:
> web page form normally returns something like:
> name=bill+clinton&eyecolor=blue&hobbies=foreign+travel+politics
>
> and I'd like the script accept it and to clear it up.
> ie: echo $FIRSTNAME
> Bill
> echo $HOBBY1
> foreign travel
> etc..
>
> any ideas?

I'd use awk. I haven't experimented with mu-awk, but I suppose it's more
or less compatible to POSIX-awk. Splitting the input records at & and the
fields at = and +, and assuming that's all there is to it (I haven't
bothered to look up the complete syntax), here's a first effort:

If the file muff.cgi contains the one line

name=bill+clinton&eyecolor=blue&hobbies=foreign+travel+politics

then the command line

awk 'BEGIN {
              RS="&"; FS="+|="
           }
           {
              for (i=1; i<NF; i++)
              {
                 print $1 i "=" $(i+1)
              }
           }' muff.cgi

produces:

name1=bill
name2=clinton
eyecolor1=blue
hobbies1=foreign
hobbies2=travel
hobbies3=politics

If you pass that to a shell, it will set the values precisely like that.
Is that okay for a start?

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: mulinux-unsubscribe@sunsite.auc.dk
For additional commands, e-mail: mulinux-help@sunsite.auc.dk



This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:15 CET