pigletwithcurls pigletwithcurls - 7 months ago 21
Bash Question

Bash- How to express 1 as 1.000

for i in {1..100}
do
result=$( echo "scale=3; sqrt($i)" | bc)
echo $result
done


Hi, when I run my code, it shows me the square root of the integers. However, it expresses 1 as 1 instead of 1.000. I want it to be 1.000 as well. I'm wondering how I can fix it.

Answer

Try this :

for i in {1..100}
do
  result=$( echo "scale=3; (sqrt($i)/1)" | bc)
done