I've just started doing bash scripts today and I need some help :(

I have a variable $BE that if the value is less than 75 or greater than 89 then I need to cap the value at these figures so I need to put an IF in I think.

My script is probably a mess but as I've said it is my first. Any help would be great. The section is the Braking menu function.

# 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

} ;
有帮助吗?

解决方案

I think what you want is something like this:

BE=$(echo "scale=2; res=(100-($S*1.86)); if (res < 75) {res=75}; if (res > 89) {res=89}; res" | bc -l)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top