Reputation: 1
I am trying to assign 2 variables floating values and then trying to store the sum in third variable but I get an error.
#!/bin/bash
x=0.1
y=1000.0
z=$((x+y))
echo $z
output is: xyz.sh: 6: xyz.sh: Illegal number: 0.1
I am unable to understand what is going wrong.
I want z to be = 1000.01
Upvotes: 0
Views: 893
Reputation: 785246
BASH doesn't support floating point arithmetic. Use bc
command instead:
z=$(bc -l <<< "$x + $y")
echo "$z"
1000.1
Upvotes: 3