1

我今天刚开始做 bash 脚本,我需要一些帮助 :(

我有一个变量 $BE ,如果值小于 75 或大于 89,那么我需要将值限制在这些数字上,所以我认为需要在 IF 中输入。

我的剧本可能一团糟,但正如我所说,这是我的第一个剧本。任何帮助都会很棒。该部分是制动菜单功能。

# Braking menu function

get_menu2 () {
    dialog --title "Braking Calculator" --msgbox "Please Record the time to travel 5 metres then press OK" 15 40 ;
    T=$(dialog --output-fd 1 --title "Braking Calculator" --inputbox "Please enter Time taken (in Seconds)" 9 30) ;
    S=$(echo "scale=2; (18/$T)" |bc -l) ;
    BE=$(echo "scale=2; (100-($S*1.86))"|bc -l) ;
    D=$(echo "scale=1; ((0-($S/3.6))/(-1.19))"|bc -l) ;
    dialog --title "Braking Calculator Results" --msgbox "


        The speed is $S Km/h
        The Min. Braking Eff. is $BE %
        The Max.Stopping Distance is $D M" 15 40
    get_menu1

} ;
4

1 回答 1

1

我认为你想要的是这样的:

BE=$(echo "scale=2; res=(100-($S*1.86)); if (res < 75) {res=75}; if (res > 89) {res=89}; res" | bc -l)
于 2013-06-07T22:28:55.720 回答