在学习CGI的过程中,遇到一个关于控制LED亮灭的问题。该问题是从网页上获得参数,在CGI中根据获得的参数重新赋值。源程序如下。该问题为:在第二个赋值的时候,如果把关于off的判断放在后面,无论获得的值是on还是off,所有关于period的赋值都为1;但是把off的判断放在前面,获得on时,period的赋值为1,获得off时,period的赋值为0.这是为什么?
#!/bin/sh
/etc/rc.d/init.d/leds stop
#type=1
#period=1
case $QUERY_STRING in
*led1*)
type=1
;;
*led2*)
type=2
;;
*led3*)
type=3
;;
*led4*)
type=4
;;
esac
case $QUERY_STRING in
*off*)
period=0
;;
*on*)
period=1
;;
# *off*)
# period=0
# ;;
esac
/bin/cat /web/aaa.template
/sbin/leds $type $period
echo "$type "
echo "$period "
echo "Content-type: text/html; charset=gb2312"
echo
#/bin/cat led-result.template
exit 0