bc flags & options
Basic usage
Evaluate an expression from a pipe.
echo "2 + 3" | bc
-l, --mathlib
Load the math library (enables s(), c(), a(), l(), e() and sets scale to 20).
echo "scale=2; 10/3" | bc -l
-q, --quiet
Suppress the welcome banner in interactive mode.
bc -q
Set decimal precision
Use scale to control decimal places.
echo "scale=4; 22/7" | bc
Float arithmetic in scripts
Common pattern for shell math with decimals.
result=$(echo "scale=2; 100 * 0.15" | bc)
Powers
echo "2^10" | bc
Square root
echo "scale=4; sqrt(2)" | bc -l
Convert bases
Convert between number bases using ibase and obase.
echo "obase=16; 255" | bc
echo "ibase=16; FF" | bc
Multiple expressions
echo "x=5; x^2 + 3*x + 1" | bc