#!/bin/bash
echo "Hit a key, then hit return."
read Keypress
case "$Keypress" in
       [A-Z] ) echo "Uppercase letter";;
       [a-z] ) echo "Lowercase letter";;
       [0-9] ) echo "Digit";;
       * ) echo "Punctuation, whitespace, or other";;
esac
 
运行结果:
[root@localhost shell实验]# ./s10
Hit a key, then hit return.
a                                                     //输入小写字母
Lowercase letter                            //显示小写字母
 
[root@localhost shell实验]# ./s10
Hit a key, then hit return.
b                                                  //输入小写字母
Uppercase letter                         //显示大写字母??????
  
[root@localhost shell实验]# ./s10
Hit a key, then hit return.
d                                                  //再次验证:输入小写字母
Uppercase letter                           //显示大写字母??????

[root@localhost shell实验]# ./s10
Hit a key, then hit return.
D
Uppercase letter
 
真是邪门,上面代码到底出了什么问题,但是当输入小写a字母时,他能够正确检测,但是当输入小写字母b、d.....时,就不能显示出小写字母了,咋为事呢?????????????
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐