expr实现字符串查找匹配 1)如果没有匹配返回0 [root@linhexiao SHell]# expr "test.test" : ".*\.pub" 0 2)如果匹配了返回匹配结束位置的字符序列号 [root@linhexiao SHell]# expr "test.pub" : ".*\.pub" 8 [root@linhexiao SHell]# expr "testsdfsdf.pub" : ".*\.pub" 14 [root@linhexiao SHell]# expr "tes.pubsafd" : ".*\.pub" 7
expr实现整数判断
[root@linhexiao shellTest]# cat juge_int.sh #!/bin/bash while true do read -p "please input :" a expr $a + 0 &>/dev/null [ $? -eq 0 ] && echo int || echo chars done