Linux - Do math operations in shell

来源:互联网 发布:java定义构造方法 编辑:程序博客网 时间:2024/06/07 00:35
转自 http://doc.dev.md/lsst/

To do math operations in shell use "expr", syntax is as follows  
Syntax:
 expr   op1   operator   op2

Where, op1 and op2 are any Integer Number (Number without decimal point) and operator can be:
+ Addition
- Subtraction
/ Division
% Modular, to find remainder For e.g. 20 / 3 = 6 , to find remainder 20 % 3 = 2, (Remember its integer calculation)
\* Multiplication (注意要有反斜线)

Notespace is required between number and operator
0 0
原创粉丝点击