5. bc
- Date:
2018-09
5.1. 命令格式
- 命令格式:
bc [options] [file …]
5.2. 所属用户
- 命令路径:
/usr/bin/bc
- 需要权限:
普通用户权限即可执行
5.3. 使用指导
bc命令是一种支持任意精度的交互执行的计算器语言。 bash内置了对整数四则运算的支持,但是并不支持浮点运算,而bc命令可以很方便的进行浮点运算,当然整数运算也不再话下。
5.4. 参数
参数及参数作用:
- -i
强制进入交互式模式。
示例:
1[user@centos6 ~]$ bc -i
2bc 1.06.95
3Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
4This is free software with ABSOLUTELY NO WARRANTY.
5For details type `warranty'. `
61*18
718
- -l
定义使用的标准数学库。
示例:
1[user@centos6 ~]$ bc -l
2bc 1.06.95
3Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
4This is free software with ABSOLUTELY NO WARRANTY.
5For details type `warranty'. `
61+2
73
- -w
对POSIX bc的扩展给出警告信息。
示例:
1[user@centos6 ~]$ bc -w
2bc 1.06.95
3Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
4This is free software with ABSOLUTELY NO WARRANTY.
5For details type `warranty'. `
61^2
71
84^5
91024
10^C
11(interrupt) Exiting bc.
- -q
不打印正常的GNU bc环境信息。
示例:
1[user@centos6 ~]$ bc -q
21+2
33
43*18
554
63/2
71
- -v
显示指令版本信息。
示例:
1[user@centos6 ~]$ bc -v
2bc 1.06.95
3Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
- -h
显示指令的帮助信息。
示例:
1
5.5. 参考实例
计算 1+2+3+..+99+100 的总和
1[root@zzjlogin ~]# seq -s + 1 100 |bc
25050
3[root@zzjlogin ~]# echo {1..100} |tr " " "+" |bc
45050