ksh splitting string - html forms

I a new to using ksh for cgi..

I want to be able to split the query_string...

ie... id=893283923name=bob

How do I specifically extract the value of id in to a variable and the name etc?

Try this:

$
$ x="id=893283923name=bob"
$ x=${x#id=}
$ echo $x
893283923name=bob
$ id=${x%name=*}
$ echo $id
893283923
$ x=${x#$id}
$ echo $x
name=bob
$

and repeat the procedure for any other fields.

thanks for your reply... I found something very useful yesterday to use as a function as it sets the variables perfectly:

{
VFLAG="0"
[[ "${1}" = "-v" ]] && VFLAG="1"
CGI_TMP1=`sed -e "s/\&/ /g;s/%\(..\)/\\\`print \\\'ibase=16\\\; \1\\\' \\\| bc \\\| awk \\\'\\\{printf\\\(\\\\\"%c\\\\\",\\\$1\\\)\\
\}\\\'\\\`/g"`

if [[ "_${CGI_TMP1}" != "_" ]]
then
for i in `eval echo "\"${CGI_TMP1}\""`
do
CGI_TMP2=`print "${i}" | sed -e "s/\"/\'/g;s/,/ /g;s/+/ /g"`
CGI_VAR="${CGI_TMP2%%=}"
CGI_VAL="${CGI_TMP2#
=}"
eval ${CGI_VAR}="\"\${CGI_VAL}\""
[[ ${VFLAG} -eq 1 ]] && print "${CGI_VAR}=\"${CGI_VAL}\""
done
fi
}

frustrated1,

You may want to look into using perl for cgi parsing and scripting. PERL is a great language for parsing text and that way you won't have to call sed/awk from within your ksh script. Just a thought.

Thanks - I am looking at learning perl now...

as you say - it seems to be the way forward for parsing cgi forms etc... thanks!

hi,

perhaps you can use the sed command to separate your string :

with ... |sed 's/name/ name/g'

and with an awk after ?