bc
calculatorlinux
The bc command is one of the most frequently used commands in Linux/Unix-like operating systems. bc The bc (basic calculator) is an arbitrary precision calculator language with syntax similar to C. It allows for interactive calculations as well as programming with variables, functions, and control statements.
Quick Reference
Command Name:
bc
Category:
calculator
Platform:
linux
Basic Usage:
bc [options] [arguments]
Common Use Cases
Syntax
bc [options] [file...] bc -l [file...]
Options
Option | Description |
---|---|
-h, --help | Print a usage message and exit |
-i, --interactive | Force interactive mode |
-l, --mathlib | Define the standard math library |
-q, --quiet | Don't print initial welcome banner |
-s, --standard | Process exactly the POSIX bc language |
-w, --warn | Give warnings for extensions to POSIX bc |
-v, --version | Print version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the bc
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
#
# Calculate a simple expression
echo "5 + 3" | bc
# Output: 8Basic Examples:
# Launch bc interactively bc
Advanced Examples:
# Convert from decimal to binary echo "obase=2; 42" | bc # Output: 101010