0

I'm new to bash and I'm trying to make a stock market (simulated) script. Now I'm trying to read an input (1 digit long) for 5 seconds, if there's none then keep on going but if there's input then call a function.

The piece of code I cannot get to work is this

while true
do
    menu
    printValues
    frames=$(($frames+1))
    read -t 5 -n 1 option
    if [ $option -ge 0 && $option -le 9 ]
    then
            buyMenu
    fi
    clear
done

If clarify is needed please reply! I appreciate the help!

  • 1
    Are you getting an error? Can you be more descriptive about what isn't working? – mlapaglia Jun 01 '18 at 18:43
  • You may find [shellcheck](https://shellcheck.net) useful. It automatically recognized [this problem](https://github.com/koalaman/shellcheck/wiki/SC2107). – that other guy Jun 01 '18 at 18:46
  • What do you mean by "keep on going"? Do you mean execute the loop again or exit the loop? – cdarke Jun 01 '18 at 18:49
  • the printvalues function updates the drops and climbs randomly generated. I want this to happen each 5 seconds of runtime. It is working fine, the values appear and they update. Well, they used to update while I was using sleep. Now with this code after the values are printed the scripts still waits the 5 seconds but if I input any number between 0 and 9 (which corresponds to the company's index, it updates the values again, without calling the buyMenu function, which is supposed to clear the screen and prompt for some values. This function ends with a simpl "read" so it should stop there – Rodrigo Pinto Jun 01 '18 at 18:51
  • keep on going means executing the loop again – Rodrigo Pinto Jun 01 '18 at 18:52

0 Answers0