简体   繁体   English

通过CGI将字符串传递给Shell脚本

[英]Pass string to a shell script through CGI

I'd like to pass a string that user submits in a simple HTML form, just like the following one, to a shell script. 我想将用户以简单的HTML格式提交的字符串(如以下示例)传递给shell脚本。
I haven't been able to find the answer so far. 到目前为止,我还没有找到答案。 I'd appreciate any hints. 我将不胜感激。

<form method="post" action="http://example.com/cgi-bin/echo.sh"> 
<input type="text" name="Text" value=""><br>
<input type="submit" value="Submit">
</form> 

And a shell script should print the value it captured. Shell脚本应打印其捕获的值。

#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Echoing argument</title>'
echo '</head>'
echo '<body>'
echo $1
echo '</body>'
echo '</html>'

This article helped to figure it out. 本文有助于弄清楚。 I had to add set $QUERY_STRING line before echo $1 . 我必须在echo $1之前添加set $QUERY_STRING行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM