For a school assignment I need to make a BMI calculator. But it needs to work with decimals. So do any of you know how I make it, so I can type in a decimal on line 4 and 5 and get a decimal result on line 13? Am new to Linux BASH scripting, so all the help I can get will be very appreciated.
1. #!/bin/bash
2. clear
3.
4. read -p "Weight in kilogram: " kg
5. read -p "Lenght in meter: " m
6. clear
7.
8. let total_weight=$kg
9. let total_lenght=$m*$m
10. let BMI=$total_weight/$total_lenght
11. clear
12.
13. echo "Ur BMI is: $BMI"
bashcan't do floats on its own. – Panki Oct 21 '21 at 14:38bashonly does integer arithmetic. Readman bcand do something likebmi=$(echo "scale=2;$total_weight / $total_length" | bc). Hints: Don't use all upper case variable names (they're used for communicating with programs, "BMI" isn't bad by itself, but upper case variable names will bite you eventually. Check your spelling.Always paste your script intohttps://shellcheck.net, a syntax checker, or installshellchecklocally. Make usingshellcheckpart of your development process. – waltinator Oct 21 '21 at 14:45