How to catch parameter value in Apache2 CGI

I have a small apache2 CGI application on Ubuntu. CGI handler bash shell script.
My client application search.html :

<html>
<body>
<form action="/cgi-bin/search.sh" method="post">
    <input type="text" name="searchKey" size="10"></input>
    <input type=SUBMIT value="search">
<form>
</body>
</html>

firstly, I just want to catch the value of the "searchKey" parameter on the server side. I tried to follow but didn't display anything. search.sh :

#!/bin/bash
echo Content-type:text/plain 
echo ""

echo $SEARCHKEY

Guys, can you tell me how to catch the parameter value on the server side?

UPDATE

thank you for all the answers. I realized that to get information about post-processing, you need to read data from STDIN.
I tried since Ithcy will suggest the following:

#!/bin/bash
echo post=$(</dev/stdin)
echo 'content length:'$CONTENT_LENGTH
echo 'content:'$post

he only displayed the following:

content length:30
content:

? Apache, ?

+3
6

POST STDIN.

#!/bin/bash
POST=$(</dev/stdin)
echo $POST

perl ( python, PHP ..), , .

+4

​​ $QUERY_STRING. , env script.

searchKey:

echo $QUERY_STRING | sed 's/searchKey\=\([^&]\+\).*/\1/'

. , , GET . =/

POST, : http://digitalmechanic.wordpress.com/2008/02/21/handling-post-data-in-bash-cgi-scripts/ .

+2

, . :

#!/bin/bash
echo
echo post=$(</dev/stdin)
echo 'content length:'$CONTENT_LENGTH
echo 'content:'$post

/bin/ bash ( , printf "\n" )

+2
+1

Try

echo $1

echo $SEARCHKEY
0

script, :

#!/bin/bash
echo 'content length:'$CONTENT_LENGTH
read StringInBox
echo $StringInBox
0

Source: https://habr.com/ru/post/1728029/


All Articles