How to catch value of parameter in Apache2 CGI
apache2, bash, cgi, shell, web-applications
Solution
POSTs will come through STDIN.
#!/bin/bash
POST=$(</dev/stdin)
echo $POST
But you really should look at using perl (or python, PHP, etc) if you can, as Glenn Jackman suggests.
Problem
I have a little apache2 CGI application on the Ubuntu. The CGI handler is bash shell script. My client application is 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 value of "searchKey" parameter in server side. I tried like following, but displaying nothing. search.sh is: ``` #!/bin/bash echo Content-type:text/plain echo "" echo $SEARCHKEY ``` Guys, can you tell me how to catch value of the parameter in the server side? UPDATE thank you for all answers.I understood that to get a value of post request need to read data from STDIN. i tried as Ithcy suggest like following ``` #!/bin/bash echo post=$(</dev/stdin) echo 'content length:'$CONTENT_LENGTH echo 'content:'$post ``` it was displaying only that: ``` content length:30 content: ``` why is content nothing? do i need to do more configure on Apache server to read post data? Thanks