I have a script that at some point will ask the interactive user a question:
#!/bin/ksh
echo "What is your access code?"
read ans
...
Sometimes this script is run by other scripts and there are no interactive users. The script then hangs on the "read" command, waiting for a user response that will never come.
I would like to have the "read" timeout after a certain period of time, and move on to the next instruction.
The box with similar threads at the bottom of this page has several promising-looking hits. In particular, Giving "read" from standard input a timeout. has a good discussion. However, you could also look at the test -t command to find out whether the script is running connected to a terminal or not.