units – conversion program

This library provides a function to comfortable use GNU units in a shell script. Thus, it gives you the possibility to do calculations with decimal and exponential numbers with and without units in shell scripts.


  • Obviously it depends on units ;)


units_clc EQUATION
Returns the result of the EQUATION. You can use here the following build-in functions: sin, cos, tan, ln, log, log2, exp, acos, atan. The EQUATION should be enclosed by quotation marks.
units_clc [-n|-u] EQUATION_with_UNITS|VALUE_with_UNITS [UNITS]
Returns the result of the EQUATION_with_UNITS or the VALUE_with_UNITS in SI units by default. With the optionial second argument [UNITS] you define the desired units of the result. You can enforce (-u) or disable (-n) the output of the units in the result string.


(default: 1) Return units in result string by default (1) or supress the units (0).



To make a simple calculation:

. libinclude.sh
import units
units_clc "(45.88*2^4-1)/1.345e3"

the script will return 0.54504089.

Calculate with units

Do a calculation with values and units:

units_clc "2.3 km + 236.5m"
units_clc "2.3 km + 236.5m" 'km'

will return ‘2536.5 m’ and ‘2.5365 km’.

Convert between units

units_clc '56*kg/m3' 'g/cm3'
units_clc -n '56*kg/m3' 'g/cm3'

returns ‘0.056 g/cm3’ and ‘0.056’

Get definition

units_clc -u '255.67e-6 J'

returns the value in SI units: ‘0.00025567 kg m^2 / s^2’