系统相关
首页 > 系统相关> > linux 中 case条件测试语句

linux 中 case条件测试语句

作者:互联网

 

1、

[root@centos7pc1 test2]# ls
test.sh
[root@centos7pc1 test2]# cat test.sh   ## 测试脚本
#!/bin/bash
read -p "please input an number or an letter: " KEY
case $KEY in
[a-z]|[A-Z])
echo "You had entered an letter!"
;;
[0-9])
echo "You had entered a number!"
;;
*)
echo "You had entered an abnormal character!"
esac
[root@centos7pc1 test2]# bash test.sh   ## 测试数字
please input an number or an letter: 6
You had entered a number!
[root@centos7pc1 test2]# bash test.sh   ## 测试字母
please input an number or an letter: U
You had entered an letter!
[root@centos7pc1 test2]# bash test.sh   ## 测试其他字符
please input an number or an letter: !
You had entered an abnormal character!

 

标签:case,语句,test2,had,number,letter,linux,test,entered
来源: https://www.cnblogs.com/liujiaxin2018/p/16104917.html