Linux Comm Bc
# Linux bc Command
[ Linux Command Reference](#)
The bc command is an arbitrary precision calculator language, typically used as a calculator under Linux.
It is similar to a basic calculator; using this calculator, you can perform basic mathematical operations.
**Common Operations:**
* + Addition
* - Subtraction
* * Multiplication
* / Division
* ^ Exponentiation
* % Remainder
### Syntax
bc(Options)(Parameters)
**Option Values**
* -i: Force interactive mode;
* -l: Define the standard math library to use;
* -w: Give warnings about extensions to POSIX bc;
* -q: Do not print the normal GNU bc environment information;
* -v: Display version information;
* -h: Display help information.
**Parameters**
File: Specifies a file containing calculation tasks.
### Examples
$ bc bc 1.06.95Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.This is free software with ABSOLUTELY NO WARRANTY.For details type `warranty'. 2+3 5 5-2 3 2+3*1 5
Type `quit` to exit.
**Using a Pipe**
$ echo "15+5" | bc 20
`scale=2` sets the decimal places; 2 means keeping two decimal places:
$ echo 'scale=2; (2.777 - 1.4744)/1' | bc 1.30
Besides using `scale` to set decimal places, bc also has `ibase` and `obase` for calculations in other bases:
$ echo "ibase=2;111" |bc 7
**Base Conversion**
#!/bin/bash abc=192 echo "obase=2;$abc" | bc
The execution result is: 11000000, which is using bc to convert decimal to binary.
#!/bin/bash abc=11000000 echo "obase=10;ibase=2;$abc" | bc
The execution result is: 192, which is using bc to convert binary to decimal.
Calculating squares and square roots:
$ echo "10^10" | bc 10000000000 $ echo "sqrt(100)" | bc 10
[ Linux Command Reference](#)
YouTip