--
My Bolg: http://niutao.cublog.cn
我今天下午试了一下,原来是if后面忘加空格了,加上空格,那一行应该没问题了,不过上面的if,then,eilf结构不对,我把代码改为: 1 #!/bin/sh
2 # Ask some questions and collect the answer
3
4 dialog --title "Questionnaire" --msgbox "Welcome to my simple survey" 9 18
5 dialog --title "Confirm" --yesno "Are you welling to take part?" 9 18
6 echo $i
7 if [ $? != 0 ];then
8 dialog --infobox "Thank you anyway" 5 20
9 sleep 2
10 dialog --clear
11 # exit 0
12 fi
13 if [ $? = 0 ];then #原代码中if后面忘加空格
14 dialog --title "Questionnaire" --inputbox "Please enter your name" 9 30 2>_1.txt
15 Q_NAME=$(cat _1.txt)
16 dialog --menu "$Q_NAME,what music do you like best?" 15 30 4 1 "Classical" 2 "Jazz" 3 "Country" 4 "Other" 2>_1.txt
17 Q_MUSIC=$(cat _1.txt)
18 fi
19 if [ "$Q_MUSIC" = "1" ];then
20 dialog --msgbox "Good choice!" 12 25
21 fi
22 sleep 5
23 dialog --clear
24
25 exit 0
在试一下,应该没问题。
很好,不过我还是要在多说两句:
1、如果你要贴出代码,那最好是"纯代码",而不要含有像上面那样的多余的行号,
发之前最好整理好再发。
2、程序一定要有格式,是别人很容易就可以看明白。
下面是我对你上面发的作的一些改进:
#!/bin/sh
# Ask some questions and collect the answer
dialog --title "Questionnaire" --msgbox "Welcome to my simple survey" 9 18
dialog --title "Confirm" --yesno "Are you welling to take part?" 9 18
echo $i
if [ $? != 0 ];then
dialog --infobox "Thank you anyway" 5 20
fi
if [ $? = 0 ];then #原代码中if后面忘加空格
dialog --title "Questionnaire" --inputbox "Please enter your name" 9
30 2>_1.txt
Q_NAME=$(cat _1.txt)
dialog --menu "$Q_NAME,what music do you like best?" 15 30 4 1
"Classical" 2 "Jazz" 3 "Country" 4 "Other" 2>_1.txt
Q_MUSIC=$(cat _1.txt)
fi
if [ "$Q_MUSIC" = "1" ];then
dialog --msgbox "Good choice!" 12 25
fi
dialog --clear
clear
exit 0
---------- Forwarded message ----------
From: 刘周平 <sanwei...@gmail.com>
Date: 2008/7/23
Subject: Re: 这个小Shell脚本运行时有问题!!
To: linuxe...@googlegroups.com
2008/7/23 Niu Tao <niuta...@gmail.com>:
>
> 2008/7/23 吴雨龙 <WYlon...@gmail.com>:
> > 我在学习Shell脚本时将书上一个Shell脚本敲进电脑,可是运行时出现了问题。不知道该怎么修改,请高手指教:
> > 程序主要问题在第六行,按理说$?表示上一条指令的返回结果,所以当选择yes后应该返回0,no后应该返回1,可是不管做什么选择,在信息框中打印出
> > 来一看都是%66,所以导致了下面的判断语句无效,程序无法继续运行。
> > #!/bin/sh
> > # Ask some questions and collect the answer
> >
> > dialog --title "Questionnaire" --msgbox "Welcome to my simple survey"
> > 9 18
> > dialog --title "Confirm" --yesno "Are you welling to take part?" 9 18
dialog --title "Questionnaire" --msgbox "Welcome to my simple survey" 9 18
dialog --title "Confirm" --yesno "Are you welling to take part?" 9 18
if [ $? = 1 ];then
dialog --infobox "Thank you anyway" 5 20
sleep 2
dialog --clear
exit 0
else
dialog --title "Questionnaire" --inputbox "Please enter your
name" 9 30 2>temp.txt
Q_NAME=$(cat temp.txt)
result=echo "Q_NAME"
dialog --menu "$Q_NAME,what music do you like best?" 15 30 4 1
"Classical" 2 "Jazz" 3 "Country" 4 "Other" 2>temp.txt
Q_MUSIC=$(cat temp.txt)
if [ "$Q_MUSIC" = "1" ];then
dialog --msgbox "Good choice!" 12 25
else
dialog --msgbox "Bad choice!" 12 25
fi
result=`echo $Q_NAME $Q_MUSIC`
echo $result >>result.txt
dialog --clear
fi
rm temp.txt
exit 0
2008/7/23 Niu Tao <niuta...@gmail.com>:---------- Forwarded message ----------
From: 刘周平 <sanwei...@gmail.com>
Date: 2008/7/23
Subject: Re: 这个小Shell脚本运行时有问题!!
To: linuxe...@googlegroups.com
2008/7/23 Niu Tao <niuta...@gmail.com>:
>
> 2008/7/23 吴雨龙 <WYlon...@gmail.com>:
> > 我在学习Shell脚本时将书上一个Shell脚本敲进电脑,可是运行时出现了问题。不知道该怎么修改,请高手指教:
> > 程序主要问题在第六行,按理说$?表示上一条指令的返回结果,所以当选择yes后应该返回0,no后应该返回1,可是不管做什么选择,在信息框中打印出
> > 来一看都是%66,所以导致了下面的判断语句无效,程序无法继续运行。
> > #!/bin/sh
> > # Ask some questions and collect the answer
> >
> > dialog --title "Questionnaire" --msgbox "Welcome to my simple survey"
> > 9 18
> > dialog --title "Confirm" --yesno "Are you welling to take part?" 9 18按大家说的都改过以后还是不行,现在作主要的问题在于下面的两个判断语句根本就不进,在上一句的选择做出后程序就自动结束了。大家谁知道这究竟是怎么回事?