Hi all,
I'm trying to "echo" some informations in a while loop, in ksh script. I want to quit, if the user enter some key...
Can anyone help me accomplish this task?
Thanks

You need to use coprocesses to have a read timeout. At least that is the only way I know to do it in ksh. bash read has a timeout
two separate scripts:
main.sh & asynch_signal.sh

asynch_signal.sh

#!/bin/ksh
# file: asynch_signal.shl  send a signal to parent process after $1 seconds
sleep $1
kill -USR2 $PPID
exit

main.sh

#!/bin/ksh

input="@@@"

# function to create asyncronous read termination
readit()
{
  trap "return" USR2
  asynch_signal.shl 10 |&
  read input
# turn off trap because we got input
  trap "" USR2

}

while [[ "$input" = "@@@" ]]
do
    echo "stuff"
    readit
done
echo "broke out of loop"
exit

Please note this is not like a keypress event in windows, the user has to hit return.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.