bc命令是Linux系统中一个基本的数学运算工具,可以实现高精度的数学运算,支持四则运算、比较运算、逻辑运算、位运算等。bc命令支持整数和浮点数,可以实现精确到小数点后任意位数的精度。
使用方法
1. 单个表达式的计算:
$ bc 2+2 4
2. 执行文件:
$ bc filename
3. 命令行参数:
$ bc -l filename
4. 命令行参数:
$ bc -q filename
bc命令参数
- -l:使用标准输入输出,支持高精度运算;
- -q:使用标准输入输出,不输出任何提示信息;
- -i:使用标准输入输出,支持交互式输入;
- -w:使用标准输入输出,设置输出宽度;
- -s:使用标准输入输出,设置输出精度;
- -c:使用标准输入输出,显示每行计算的结果;
- -e:使用标准输入输出,执行命令行参数的表达式;
- -h:显示帮助信息。
实例
$ bc 2+2 4 $ bc -l 2+2 4 $ bc -q 2+2 4 $ bc -i 2+2 4 quit $ bc -w 10 2+2 4 $ bc -s 10 2+2 4.0000000000 $ bc -c 2+2 2+2 4 $ bc -e 2+2 4 $ bc -h Usage: bc [options] [file ...] Options: -l Load & use the standard math library -q Quiet mode -i Interactive mode -w width Set the output width -s scale Set the output scale -c Show each line result -e Evaluate the expression -h Display this help