linux中常用计算方法
bc
yum install bc
[root@hecs-98663 ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1+2
3
1--5
(standard_in) 2: syntax error
1-5
-4
10/2
5
13/5
2
2^3
8
8%3
2
11%2
1
quit
[root@hecs-98663 ~]# bc -l
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
13/5
2.60000000000000000000
quit
calc
[root@hecs-98663 ~]# calc
C-style arbitrary precision calculator (version 2.12.5.0)
Calc is open software. For license details type: help copyright
[Type "exit" to exit, or "help" for help.]
; 1+5
6
; 2^3
8
; 9^0.5
3
; 13/5
2.6
; quit
非交互式
[root@hecs-98663 ~]# calc 3/5
0.6
expr
[root@hecs-98663 ~]# expr 4 \* 5
20
[root@hecs-98663 ~]# expr 4 \^ 2
expr: 语法错误
[root@hecs-98663 ~]# expr 2 + 3
5
shell命令
[root@hecs-98663 ~]# echo $((2+3))
5
awk命令
cat data | awk '{sum+=$1} END {print "Sum = ", sum}' # 计算data文件里数据之和

浙公网安备 33010602011771号