cgiparse command

Purpose

Use the cgiparse command to parse the QUERY_STRING environment variable for CGI scripts. If the QUERY_STRING environment variable is not set, the command reads CONTENT_LENGTH characters from its standard input. All returned output is written to its standard output.

Format

   cgiparse -Flag [Modifier]

Parameters

Flags, their one-character equivalents (-k -f -v -r -i -s -p -c -q -P) and their function, include:

-keywords | -k
Parses QUERY_STRING for keywords. Keywords are decoded and written to standard output, one per line.
-form | -f
Parses QUERY_STRING as form request. Returns a string which, when evaluated by the shell, sets shell variables with the prefix FORM_ followed by a field name. Field values are the contents of the variables.
-value field-name | -v field-name
Parses QUERY_STRING as form request. Returns only the value of field-name.
-read | -r
Reads CONTENT_LENGTH characters from standard input and writes them to standard output.
-init | -i
If QUERY_STRING is not set, reads the value of standard input and returns a SET statement that sets QUERY_STRING to this value. This can be used with both the GET and POST methods. A typical use is:
eval 'cgiparse -init'

This sets the QUERY_STRING environment variable, regardless of whether the GET or POST method was used.

cgiparse can be called multiple times in the same script when the GET method is used, but it must only be called once if the POST method is used. With the POST method, after standard input is read, the next cgiparse finds standard input empty and waits indefinitely.

-sep separator | -s separator
Specifies the string used to separate multiple values. If you are using the -value flag, the default separator is newline. If you are using the -form flag, the default separator is a comma (,).
-prefix prefix | -p prefix
Used with -POST and -form, specifies the prefix to use when creating environment variable names. The default is "FORM_".
-count | -c
Used with -keywords, -form, and -value, returns a count of items related to these flags.
-keywords | -k
Returns the number of keywords.
-form | -f
Returns the number of unique fields (multiple values are counted as one).
-value field-name | -v field-name
Returns the number of values for field-name (if there is not a field named field-name, output is 0).
-number
Used with -keywords, -form, and -value, returns the specified occurrence related to these flags.
-keywords
Returns the n'th keyword. (For example -2 -keywords outputs the second keyword.)
-form
Returns all the values of the n'th field. (For example -2 -form outputs all the values of the second field.)
-value field-name
Returns the n'th of the multiple values of field field-name. (For example -2 -value -whatsit outputs the second value of the whatsit field).
-quiet | -q
Suppresses all error messages. (Non-zero exit status still indicates error.)
-POST | -P
Information from standard input (or if a filename is intended, the stdin file) is directly decoded and parsed into shell variables, QUERY_STRING is not used. -POST is equivalent to consecutive use of the -init and -form options.

Examples

The following examples ignore the fact that, in reality, QUERY_STRING is already set by the server. In the following examples, $ is the Bourne shell prompt.

Results

0
Success
1
Illegal command line
2
Environment variables not set correctly
3
Failed to get requested information (for example, there is no such field or QUERY_STRING contains keywords when form field values are requested)
Note:
When you receive one of these error codes, you may receive additional informational messages, too. The message varies depending on the command issued.