0

I am trying to build a simple BMI calculator for my college project but I am having error while using if statements. I am new to shell scripting so I don't know much about it. I think the problem is because I am using bc command because if remove the if statements it still gives me 0 answer.

Here is my code

# --------------------BMI calculator---------------------
weight="0"
height="0"
BMI="0"
echo "Welcome to BMI calculator"
echo "Please enter your weight in kilograms: "
read weight
echo "Please enter your height in meters: "
read height
if [ "$height > 0" | bc ] & [ "$weight > 0" | bc ]
then
BMI="$weight/($height*$height)" | bc
        echo "Your BMI is $BMI"
else
        echo "Invalid inputs!!"
fi

Please let me know if there are any other error as well

0 Answers0