linux中shell判断字符为字母例子

作者:简简单单 2016-10-16

判断输入的字符为字母

[root@LinuxEA awk]# cat 111com.net
#!/bin/sh
read linuxea
if [[ $linuxea =~ ^[a-zA-Z]+$ ]]; then
        echo "ok"
else
        echo "error"
fi
[root@LinuxEA awk]#
执行如下:

[root@LinuxEA awk]# bash 111com.net
123
error
[root@LinuxEA awk]# bash 111com.net
acB
ok
[root@LinuxEA awk]# bash 111com.net
1A
error
[root@LinuxEA awk]# bash 111com.net
A1
error
[root@LinuxEA awk]# bash 111com.net
aa
ok

相关文章

精彩推荐