Linux脚本设计练习2——一个游戏菜单的简单实现
入门级linux编程新手,学到case语句,用shell编写了一个游戏菜单,随着后面的学习,肯定还需要很多优化,先当作练手,加深学习印象吧。~~
写这个程序时候犯的错误有
1.引用变量时候没有加上$
2.用中括号包[]包含条件时,中括号必须与关键字及运算符中间有空格隔开,否则会报符号方面的错误。这些都是一些细节问题,并非使用语法上的问题,但是往往会导致整个程序挂掉。
echo "Welcome To Play" echo "Please input one number to select one menu" echo "1.Start one new game" echo "2.Continue the old game" echo "3.Charge" echo "4.Exit" echo "5.Help" read menuValue case $menuValue in 1) echo "1.Single Model" echo "2.Online Model" echo "Input one number to select one menu" read modelChoose case $modelChoose in 1) echo "Starting Single Model" ;; 2) echo "Starting Online Model" ;; *) echo "Please input number 1 or 2" esac ;; 2) echo "1.Archive saved in 2012.3.1" echo "2.Archive saved in 2013.3.2" echo "3.Archive saved in 2013.3.3" echo "Input one number to select one menu" read archiveValue case $archiveValue in 1) echo "Starting Archive saved in 2012.3.1" ;; 2) echo "Starting Archive saved in 2013.3.2" ;; 3) echo "Starting Archive saved in 2013.3.3" ;; *) echo "Please input archive number existed" esac ;; 3) echo "1.ABC Bank" echo "2.CBC Bank" echo "3.PBC Bank" echo "Input one number to select one bank" read bankValue case $bankValue in 1) echo "Enterring into ABC Bank" ;; 2) echo "Enterring into CBC Bank" ;; 3) echo "Enterring into PBC Bank" ;; *) echo "Please input bank number existed" esac ;; 4) echo "1.Sure to Exit" echo "2.Return to the main menu" echo "Input one number to select one menu" read exitValue case $exitValue in 1) echo "You will exit the game" ;; 2) echo "You will return to the main menu" ;; *) echo "Please select the right menu" esac ;; 5) echo "1.How to operate the game" echo "Input one number to select one menu" read operateValue case $operateValue in 1) echo "Method to operate the game" ;; *) echo "Input the right number" esac ;; *) echo "Input the right number" esac