藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年6月26日 11:18


請教如何用shell實現選擇...

如下所示:
[code]echo "Please select the machines's type,then press enter key"
echo "1.008"
echo "2.009"
echo "3.010"
echo "4.011"
echo "5.exit"[/code]
在read用戶的輸入後.用case語句
[code]read test
case $test in
   1)
    func1
    ;;
    2)
    func2
    ;;
    3)
     func3
    ;;
     4)
     func4
     ;;
      5)
      exit
      ;;
      *)
       echo "invalid input,now exit"
       exit
       ;;
esac
[/code]
請問這裡在用戶輸入非法之後,能否讓用戶select again,而不是exit,謝謝...

請教如何用shell實現選擇...

用while來做
[code]
Sex1=None
while [ $Sex1 = None ]
  do
echo '你的性別? 1)男性 2)女性 3)中性'
read Sex1
case $Sex1 in
1)
   Sex='男性'
   Sex1='Male'
   ;;
2)
   Sex='女性'
   Sex1='Female'
   ;;
3)
   if [ $PlayerType = '機器人' -o $PlayerType = '機器狗' ]
     then
       Sex='中性'
       Sex1='Neuter'
     else
       Sex1='None'
       echo -e "$cFR選擇錯誤!你個不陰不陽的傢伙只能選擇男性或女性。$cFG"
    fi
   ;;
*)
   Sex1='None'
   echo -e "$cFR選擇錯誤!請選擇對應性別的數字鍵後按回車鍵!$cFG"
   ;;
esac
done
[/code]

請教如何用shell實現選擇...

把所有這些代碼組成fun5,在非法輸入的時候遞歸,可以嗎?

請教如何用shell實現選擇...

謝謝樓上兩位兄弟...



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com