bash - Why does read's timeout break my console?

08
2014-07
  • Hashbrown

    I have a script that is causing an issue, I've boiled it down to this;

    #/bin/bash
    read -t 1 -p 'Wanna continue?'
    less +F readTimeout.sh
    echo 'Wont get printed'
    

    The original script operated by prompting the user to continue, but after waiting for five seconds (in this case, one) it will continue on its own.
    It then proceeds to tail from a log file (in this case, itself, for demonstrative purposes).
    Then it should execute the rest of the commands after the user closes less.

    Well, when less is in tail mode, you need to hit ctrl+c to stop it from following the file (then you can scroll/search on what's in less so far, or shift+f to follow again, or Q to quit).

    The problem for this script is, when you ^C it kills less, takes you back to prompt (i.e. the rest of the commands aren't ran) and stops anything you type from being echoed (if you hit enter your commands are actually being written to the console, though)!

    Without the -t switch on read (or if you respond before the timeout) it works fine.
    Any ideas why this happens &/or how to combat this? So far I've resorted to just forcing the user to respond to the prompt (i.e. removing the timeout flag from read)

    P.S.
    This is terminal emulator independent (tested konsole and xterm).
    And I've tried placing stty sane after the read line in case it would fix it.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    bash - on quit, 'less' does NOT clear its contents when run in a 'screen' session
  • gojira

    Possible Duplicate:
    Using screen, commands like less and man don't clear the screen afterwards

    When I quit 'less' in a normal bash, it clears the previous contents displayed by 'less' and shows the bash contents again. This is the defualt behavior and what I desire.

    However, when I use 'less' in a 'screen' session (still bash inside the screen session), after quitting it does not erase the contents shown by 'less' and the contents of bash are gone (still having a new bash comand line prompt though).

    How can I make it so that less does clear its display after quitting, even though I am using it within a 'screen' session?


  • Related Answers
  • Dennis Williamson

    Try adding this command to your ~/.screenrc file:

    altscreen
    

    You can also do Ctrl-a : altscreen from within screen to toggle it on or off in the current session.

    Make sure your $LESS environment variable does not contain X in its value.

  • Mikel

    Also check that these work:

    $ tput smcup | od -c
    $ tput rmcup | od -c
    

    they should print something like:

    0000000 033  [  ?  1  0  4  9  h
    

    rather than:

    0000000