Linux command
bc 命令
文本
涉及管道、覆盖或删除,执行前请先确认路径和参数。
常用示例
Calculate
echo ["2+2"] | bc
Division
echo ["scale=2; 10/3"] | bc
Run
bc [script.bc]
Math library
bc -l
Evaluate an expression
bc -e "[scale=2; 100/3]"
Interactive
bc
说明
bc is an arbitrary precision calculator language. It supports interactive calculation, scripting, and mathematical operations with user-definable precision for decimal calculations. The tool has been a Unix standard for decades and is widely used in shell scripts for arithmetic.
参数
- -l, --mathlib
- Load math library (includes functions like s, c, a, l, e, and sets scale to 20)
- -s, --standard
- POSIX standard mode; error on any non-POSIX extensions
- -q, --quiet
- Don't print the normal GNU bc welcome banner
- -i, --interactive
- Force interactive mode
- -w, --warn
- Warn about POSIX non-compliance
- -e _expression_, --expression _expression_
- Evaluate expression; multiple -e options are processed in order
- -v, --version
- Print version number and exit
FAQ
What is the bc command used for?
bc is an arbitrary precision calculator language. It supports interactive calculation, scripting, and mathematical operations with user-definable precision for decimal calculations. The tool has been a Unix standard for decades and is widely used in shell scripts for arithmetic.
How do I run a basic bc example?
Run `echo ["2+2"] | bc` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -l, --mathlib do in bc?
Load math library (includes functions like s, c, a, l, e, and sets scale to 20)