echo '2 + 3 * 4' | bc
echo 'scale=4; 10 / 3' | bc # 3.3333 (scale = digits after the decimal point)
echo 'sqrt(2)' | bc -l # -l loads the math library (scale defaults to 20)
echo 'ibase=16; FF' | bc # hex to decimal: 255
echo 'obase=2; 10' | bc # decimal to binary: 1010
bc <<< '2^64' # arbitrary precision integers
Bash arithmetic ($(( ))) only handles integers, so bc fills the gap for decimals. Example: percent full in a script: echo "scale=1; 100 * $used / $total" | bc.