Last active
December 25, 2015 06:09
-
-
Save winwu/6930081 to your computer and use it in GitHub Desktop.
shell script 練習
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -p "How about your Height(cm)?" height | |
read -p "How about your Weight(kg)?" weight | |
echo "your height is $height cm" | |
echo "your weight is $weight kg" | |
#because i need chage height's cm to m, and 1m = 100cm | |
m=100 | |
height=`echo "scale=2; $height / $m"|bc` | |
BMI=`echo "scale=2; $weight / ($height*$height)" |bc` | |
echo "---------Result---------" | |
echo "your bmi is $BMI" | |
#設定值(set value時)不能有 $ 在前面 | |
#取值(get value)要有 $ | |
#四則運算要使用 expr, +-*/ 左右都要有空白 | |
#不過因為要取到小數點第二位,因此在這裡就不用 expr | |
#所以不用在乎 expr 使用加減乘除運算的規定(ex: +-*/ 左右要空白) | |
echo "below 18.5 | 偏瘦" | |
echo "18.5-24.9 | 標準" | |
echo "25.0-29.9 | 超重" | |
echo "30.0 above | 肥胖" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment