1. [[email protected] scripts]# cat fruit_menu.sh
2. #!/bin/sh
3. menu(){
4. cat <<END
5. ======================
6. 1.apple
7. 2.pear
8. 3.banana
9. 4.cherry
10. 5.exit
11. ======================
12. END
13. }
14. while true
15. do
16. menu
17. read -p "please slect the fruit representing:" a
18. case "$a" in
19. 1) echo-e "\033[31m apple \033[0m"
20. ;;
21. 2) echo-e "\033[32m pear \033[0m"
22. ;;
23. 3) echo-e "\033[33m banana \033[0m"
24. ;;
25. 4) echo-e "\033[34m cherry \033[0m"
26. ;;
27. 5) exit 0
28. ;;
29. *) echo""
30. echo"No slect the fruit representing"
31. echo""
32. ;;
33. esac
34. done
第二种:
1. [[email protected] scripts]# cat case_02.sh
2. #!/bin/bash
3. usage(){
4. echo "Usage:$0content {red|green|yellow|blue|purple}"
5. exit 1
6. }
7. [ $# -ne 2 ] && usage
8. case "$2" in
9. red|RED) echo -e "\033[31m $1 \033[0m"
10. ;;
11. green|GREEN)echo -e "\033[32m $1 \033[0m"
12. ;;
13. yellow|YELLOW)echo -e "\033[33m $1 \033[0m"
14. ;;
15. blue|BLUE)echo -e "\033[34m $1 \033[0m"
16. ;;
17. purple|PURPLE)echo -e "\033[35m $1 \033[0m"
18. ;;
19. *)usage
20. ;;
21.
22. esac