Why does read's timeout break my console?

1

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.

Hashbrown

Posted 2014-01-31T03:51:50.803

Reputation: 1 720

The script works fine for me. Can you provide more details about your system? – rici – 2014-01-31T17:40:17.180

CentOS 6.4, what would you like to know? – Hashbrown – 2014-02-01T01:48:10.877

No answers