PDA

View Full Version : Help with bash read to get user input



sarang
January 14th, 2009, 05:00 PM
Hello folks,
I have the following problem while trying to read the user's response from a bash script:

If the user continues to type things after my first read has read whatever it wants (i.e one character if -n1 option is used, or till the newline character or IFS otherwise), those things are not discarded either by bash or my gnome-terminal (i.e the read buffer is not flushed). The result of this is that those characters are passed on as user input to my next read, causing problems. I have tried to overcome this by reading to an array (with -a) and unsetting the array before the next read, but that does not work.

How do I make this work?

Thanks in advance!