expr 数字操作

expr 可以用于计算

[root@rhel6 script]# expr 2*2
2*2
[root@rhel6 script]# 

 

使用expr来判断输入的变量是否为整数, 注意这里的&表示  安静模式(没有输出)

[root@rhel6 script]# i=123
[root@rhel6 script]# expr $i + 1 &>/dev/null
[root@rhel6 script]# echo $?
0

[root@rhel6 script]# k=abc
[root@rhel6 script]# expr $k + 1 &>/dev/null
[root@rhel6 script]# echo $?
2

 

使用expr计算字符串的长度

[root@rhel6 script]# echo $i
123
[root@rhel6 script]# expr length $i
3

 

posted @ 2017-03-14 14:44  Vincen_shen  阅读(201)  评论(0编辑  收藏  举报