case语句功能上与if语句比较类似
格式为:
#!/bin/bash
RED_COLOR='\E[1;33m'
RES='\E[0m'
read -p "please input a number:" ans
case "$ans" in
1)
echo -e "the number is ${RED_COLOR}"$ans."${RES}"
;;
2)
echo "the number is 2"
;;
[3-9])
echo "the number is $ans"
;;
*)
echo "the num you input must be less 9"
exit
;;
esac
##前面的条件既可以单个,也可以多个,并且可以选择颜色
[root@localhost test]# echo -e "\033[36m 黑色字oldboy trainning \033[0m"
黑色字oldboy trainning
##如果需要改变颜色,将36改变为其他数字即可
并且:
31 红色
32 绿色
33 黄色
34 深蓝
35 紫色
36 天蓝
37 灰色
背景颜色:40~47