我正在尝试使用Linux中的Bash shell创建一个脚本来计算BMI。我知道这只是一些傻乎乎的事情,但似乎无法使它正常工作。它不会做除法运算。你能看出我错在哪里吗?
#!/bin/bash
#==============================================================
# Script Name: bmicalc
# By: mhj
# Date: March 25, 2014
# Purpose: calculates your bmi from your weight & height
#===============================================================
#Get your weight and height
echo -n "What is your weight in pounds? "
read weight
echo -n "What is your height in inches? "
read height
#calculate your bmi
let total_weight=$weight*703
let total_height=$height*$height
bmi=$total_weight/$total_height
echo "Your weight is $weight"
echo "Your height is $height"
echo -n "Your BMI is $bmi"
let
是过时的语法;现代形式是total_weight=$(( weight * 703 ))
,total_height=$(( height * height ))
等。 - Charles Duffy