Integer operations in shell scripts are generally implemented by the two instructions of let and expr, such as the variable s plus 1 can be written: let "s = $s + 1" or s= ' expr $s + 1 '
The two are not easy to write, but the performance of the comparison can be an example to show you:
1. Expr script and execution time:
#!/bin/bashs=0while [$s-lt 10000]do s= ' expr $s + 1 ' echo $s >>/dev/null 2>&1done[[email protected] ~]# time sh expr.sh real 0m50.776suser 0m11.528ssys 0m39.601s
2. Let script and execution time:
#!/bin/bashs=0while [$s-lt 10000]do let "s = $s + 1" echo $s >>/dev/null 2>&1done[[email protected ] ~]# time sh let.sh real 0m0.875suser 0m0.676ssys 0m0.199s
With the above two examples, it goes without saying that it is clear that let's win with super-high advantage, so get expr dozens of times times!
Transferred from: http://yooma.blog.51cto.com/6965726/1187063/
Let and expr shell operations compare let's win