DEV Community

loading...

Discussion on: 🚀 The Missing Shell Scripting Crash Course

Collapse
pystar profile image
Pystar

Hello @dsbarnes ,
You can not do floating point arithmetic natively in Bash, but there is a trick I use i.e. using the 'bc' command like:

echo "3.142 + 3.142" | bc -l # add the value of pi to itself
echo "sqrt(49)" | bc -l # find the square root of 49
echo "scale=2; sqrt(91)" | bc -l # To find the square root of 91 to just 2 decimal places.

The capabilities of bc is extremely wide. Check the Manpage for its full documentation.