1

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

} ;
1
  • Would you kindly consider trimming your code excerpt down to the relevant part? The one you are actually asking about. That would massively improve the chances of you getting a useful answer. Commented Jun 7, 2013 at 21:57

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, It looks like what I'm needing I'll go and give it a try.
That done the trick, Thank you very much its much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.