- 论坛徽章:
- 0
|
本帖最后由 afton 于 2011-02-20 12:57 编辑
- #!/bin/bash
- clear
- until echo $1 | grep -s "^[-+]*[0-9][0-9]*$" && echo $2 | grep -s "^[-+]*[0-9][0-9]*$"
- do
- echo "USAGE:You have selected an INVALID integer."
- echo "Please re-enter these two positive integers, seperated by sapce: "
- done
- echo
- # Menu Items and prompt user
- cat <<+
- MENU
- a. Display the sum of the two numbers.
- b. Display the product of the two numbers.
- c. State whether the two individual numbers are ODD or EVEN.
- d. Display the higher of the two numbers
- e. Select the number which you like
- f. Quit the script (Exit)
- +
- # Menu Items and prompt user
- read -p "Please select options(a,b,c,d,e or f):" choice
- until [ $choice = "a" ] || [ $choice = "b" ] || [ $choice = "c" ] || [ $choice = "d" ] || [ $choice = "e" ] || [ $choice = "f" ]
- do
- clear
- echo
- cat <<+
- MENU
- a. Display the sum of the two numbers.
- b. Display the product of the two numbers.
- c. State whether the two individual numbers are ODD or EVEN.
- d. Display the higher of the two numbers
- e. Select the number which you like
- f. Quit the script (Exit)
- +
- read -p "Please select options(a,b,c,d,e or f):" choice
- done
- case $choice in
- "a") echo "$1 + $2 = $(($1+$2))"
- ;;
- "b") echo "$1 * $2 = $(($1*$2))"
- ;;
- "c") if test $(($1 %2)) -eq 0
- then
- echo "$1 is an EVEN number."
- else
- echo "$1 is an ODD number."
- fi
- if test $(($2 % 2)) -eq 0
- then
- echo "$2 is an EVEN number."
- else
- echo "$2 is an ODD number."
- fi
- ;;
- "d") if test $(($1 - $2)) -gt 0
- then
- echo "$1 is higher."
- elif test $(($1-$2)) -eq 0
- then
- echo "These two numbers are equal."
- else
- echo "$2 is higher."
- fi
- ;;
- "e") echo
- read -p "Do you like the first number or second number best (enter "first" or "second")? : " like
- until [ $like = "first" ] || [ $like = "second" ]
- do
- read -p "Do you like the first number or second number best (enter "first" or "second")? : " like
- done
- if test $like = "first"
- then
- echo "I agree."
- else
- echo "I disagree."
- fi
- ;;
- "f") exit
- ;;
- esac
复制代码 这是我写的,现在的问题是,在选择完abcd后就直接退出了,没有让用户再做其它选择
还有两个参数在命令行输入,如果输入./lab.bash 2 4 运行时正常
但如果输入./lab.bash a 3
请问怎么解决? |
|