Strange behavior from 'read' statements. (ksh - but could be same on other shells)

I'm getting rather frustrated with an interactive script I'm writing.

The script is divided up, with section for setting variable at the top, then functions (which make up most of the script) then basically a line at the end which calls the first function- the program moves between the functions to do it's thing.

The problem I'm having is when I'm using 'read' to ask the user to 'press return to continue' or suchlike, at some points in the script this works FINE, however at other points it just continues straight through the 'read' without waiting for input or anything. Using 'read -u' had no effect, I have also replaced all these prompts with the following function;

pressreturn() {
echo
echo "Press <RETURN> to continue."
read BLANK
}

This has had no positive effect, the script still ignores the read statement some of the time!

I'm using ksh version M-11/16/88f on AIX 5.2

Thanks for your time on this, folks. I know I havn't provided too much information, I was just hoping this was a not-uncommon gotcha that a few of you might have come up against at one point or another. If anyone requires further information please shout and I'll supply whatever you need.

Regards,

Alex

echo > /dev/tty
echo "Press <RETURN> to continue." > /dev/tty
read BLANK < /dev/tty

Many thanks, Perderabo, that worked a treat. Can you explain, or preferably point me to a website/free resource where I can read up on why your solution works. I have a few guesses but this whole thing has highlighted large gaps in my knowledge of UNIXland...

Again, many thanks!

Sometimes you are running with input redirected from a file. So "read BLANK" just reads one line from that file.

Does this happen without me explicitly requesting it. I know that from the shell you can do this by calling <program> thus '<program> < inputfile', is this what you mean? If so, then how is this happening when I'm not requesting it? Thanks and regards - Alex.

The shell only does what you tell it to. I have no way to guess the specifics of what you did.