Hello everyone,
I would like some help on an issue I have related to the read command with ksh93 (Unix AIX).
I want to implement a 'press any key to exit' scenario.
I have the following code:
STTY=$(stty -g)
if [ -t 0 ];then
stty -echo -icanon time 0 min 0
fi
k=""
while [[ "x$k" = "x" ]];do
read k
# following is a group of command that retrieve data from several files
# and process the data summarizing and filtering it (using awk).
# This section could possibly take 1 to 2 seconds to complete its job
# the final command does a cat of the generated data file to the screen
# then the loop would start again retrieving fresh stats from files....
........
done
stty $STTY
When I execute the code and press any key while it is executing, sometimes it exits properly, other times it takes more than one key press to exit, maybe because the key got pressed while the processing section of the loop was running. What could be 'chewing up' the pressed keystroke?
Do you have suggestions on how to guarantee termination on a single key stroke?
Maybe I need to redesign my loop logic ?
I am open to any advice and suggestion.
Thanks to all!