Square root

Basic types / Numbers / Mathematical operations

#bash has no fractional numbers and no sqrt; bc has sqrt()
number=100
result=$(bc <<< "sqrt($number)")
#result is 10

#scale sets the digits after the point
result2=$(bc <<< "scale=5; sqrt(2)")
#result2 is 1.41421

#awk has sqrt() too
fromAwk=$(awk -v x=2 'BEGIN { print sqrt(x) }')
#fromAwk is 1.41421

echo "result is $result"
echo "result2 is $result2"
echo "fromAwk is $fromAwk"