我正在使用破折号,我需要创建将解析查询字符串并将每个值保存到变量的 CGI 脚本
OLDIFS=$IFS
// use & as delimeter
IFS='&'
//this will loop the queryString variable
for line in $queryString;
do
//check if the key = action, if the condition was satisfied it will save the line to a variable..
//if the key is equal to type etc. etc.
echo "{$line,1}"
if[{$line,0:7}="action="]
then
cgi_action={$line:8}
elif[{$line:0:5}="type="]
then
cgi_type={$line:6}
fi
done
IFS=$OLDIFS
我确定我在获取行(或字符串)的子字符串时出错,但请让我们关注我在 for 循环中放置 if 语句时遇到的错误。在破折号 shell 脚本中,在 for 循环中编写 if 条件的正确方法是什么。
附加信息,我使用的是 ubuntu 14.04,