FMeinicke's Wiki

Home

❯

Linux

❯

Shells

❯

bash

❯

General

❯

Divide variables

Divide variables

May 26, 20251 min read

  • bash/arithmethic-expression
  • linux/bc

arithmethic-expression bc

Source

  • https://stackoverflow.com/a/30398152/12780516
  • using an arithmetic expression ($(( $a / $b ))) only gives an integer result
  • use bc for proper floating point math
a=100
b=42
echo $a / $b = $(bc <<<"scale=2; $a / $b")

Graph View

Created with Quartz v4.5.0 © 2025

  • GitHub