With bash you can do "read -t 5" to timeout read after 5 seconds.
However with bourne shell on AIX, you can't do that as there's no -t
option on the read.
I've been through some of the postings on here about this but none of
the suggestions have worked. The closest was:
stty min 0 time 20 #'40' is for 4 seconds timeout
echo "Enter somthing : \c"
The timeout works with this but you can't see what you're typing
because of the stty -echo. If you comment this line out, the timeout
doesn't work though.
Could someone suggest a bourne shell solution (not C or Korn) which
might be able to do this please?
Thanks a lot.
Note that I don't think recent versions of AIX have a Bourne
shell (at least not in a usual place). Modern UNIXs now have a
POSIX conformant shell as /bin/sh (most often a ksh or ksh
You could try something like:
trap : ALRM
trap 'kill "$pid" 2> /dev/null' EXIT
(sleep "$1" && kill -ALRM "$$") & pid=$!
kill "$pid" 2> /dev/null
trap - EXIT
read_timeout 20 var
printf 'Got: "%s" as $var\n' "$var"
There are race conditions, though.
Thanks for your reply. Unfortunately it didn't work. After the kill
-ALRM it still waits for input.
+ trap : ALRM
+ trap kill "$pid" 2> /dev/null EXIT
+ read var
+ sleep 2
+ kill -ALRM 647398
Try after replacing ALRM with USR1.