Bash 参数从URL导入shell脚本
如何将URL参数(如/?photo=1.png)作为变量放入shell脚本中,并运行到apache上的cgi bin容器中 编辑 Iam生成目录中所有文件的列表Bash 参数从URL导入shell脚本,bash,apache,shell,Bash,Apache,Shell,如何将URL参数(如/?photo=1.png)作为变量放入shell脚本中,并运行到apache上的cgi bin容器中 编辑 Iam生成目录中所有文件的列表 #!/bin/bash echo "Content-type: text/html" echo for file in /var/www/html/export/tui/*; do echo "<a href='/cgi-bin/test.cgi?file="${file: -27}"'>"${f
#!/bin/bash
echo "Content-type: text/html"
echo
for file in /var/www/html/export/tui/*;
do
echo "<a href='/cgi-bin/test.cgi?file="${file: -27}"'>"${file: -27}"</a><br>";
done;
#/bin/bash
echo“内容类型:文本/html”
回音
文件位于/var/www/html/export/tui/*;
做
回声“
”;
完成;
现在,我想将文件名作为参数输入到第二个脚本中,谁需要它来读取它。我找到了一个解决方案,谁可以将URL参数输入到我的脚本中
#!/bin/bash
echo "Content-type: text/html"
echo
function cgi_decodevar()
{
[ $# -ne 1 ] && return
local v t h
t="${1//+/ }%%"
while [ ${#t} -gt 0 -a "${t}" != "%" ]; do
v="${v}${t%%\%*}" # digest up to the first %
t="${t#*%}" # remove digested part
if [ ${#t} -gt 0 -a "${t}" != "%" ]; then
h=${t:0:2}
t="${t:2}"
v="${v}"`echo -e \\\\x${h}`
fi
done
echo "${v}"
return
}
function cgi_getvars()
{
[ $# -lt 2 ] && return
local q p k v s
case $1 in
GET)
[ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
;;
POST)
cgi_get_POST_vars
[ ! -z "${QUERY_STRING_POST}" ] && q="${QUERY_STRING_POST}&"
;;
BOTH)
[ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
cgi_get_POST_vars
[ ! -z "${QUERY_STRING_POST}" ] && q="${q}${QUERY_STRING_POST}&"
;;
esac
shift
s=" $* "
while [ ! -z "$q" ]; do
p="${q%%&*}"
k="${p%%=*}"
v="${p#*=}"
q="${q#$p&*}"
[ "$1" = "ALL" -o "${s/ $k /}" != "$s" ] && \
export "$k"="`cgi_decodevar \"$v\"`"
done
return
}
cgi_getvars BOTH ALL
echo $foo
你能举例说明你想怎么做吗?具有预期输出的示例输入。您的文件看起来如何?给一个这样的文件名?我不知道如何将URL参数作为变量放入shell脚本中?文件名看起来如何?我的文件名看起来像“test.cgi”