expr tips

expr implements string search and match
1) If there is no match return 0
[root@linhexiao SHell]# expr "test.test" : ".*\.pub"
0
2) If there is a match, return the character sequence number at the end of the match
[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 implements integer judgment

[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

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326711034&siteId=291194637