bc
ShellFundamentals In simulator In real LinuxArbitrary-precision calculator
Name: bc = basic calculator
You can practise it right away in the simulator, and use it in real Linux mode too.
Description
bc is an arbitrary-precision calculator language, used interactively or fed expressions through a pipe. The scale variable sets decimal places and -l loads the math library (sine, log …). The shell only does integers, so bc handles decimals.
Syntax
bc [OPTION]... [FILE]...Common options
| -l / --mathlib | Load the math library (20 decimal places) |
| -q / --quiet | Do not print the welcome banner |
| scale=N | Keep N decimal places |
| ibase / obase | Input / output base: echo "obase=2; 10" | bc gives 1010 |
| sqrt( ) | Square root, e.g. echo "scale=3; sqrt(2)" | bc |