BC(1)
NAME
bc — evaluate arithmetic expressions
SYNOPSIS
bc <expression> bc echo "<expression>" | bc
DESCRIPTION
A safe arithmetic calculator. Pass an expression as the argument, pipe it in, or run bc with no argument for an interactive prompt (type quit to leave).
Supported: + - / % and ^ (power, also *), parentheses, unary minus, and decimal/scientific numbers (e.g. 1.5e3). Functions: sqrt, abs, round, floor, ceil, ln, log (base 10), exp, sin, cos, tan. Constants: pi, e. Separate several expressions with ; or newlines.
The expression is parsed and evaluated by a small built-in parser — never by eval() — so untrusted input cannot run code.
EXAMPLES
bc "2 + 2 3" bc "(1 + 2) ^ 10" bc "sqrt(2)" bc "sin(pi / 2)" echo "21 2" | bc