差出人man ksh
:
TMOUT
ゼロより大きい値に設定されている場合、PS1プロンプトを発行してから所定の秒数以内にコマンドが入力されないと、シェルは終了します。シェルは、この値の上限を超えてコンパイルすることはできません。
これがSolarisread
で機能するかどうかはわかりません。ksh
ksh93で動作しますが、そのバージョンにはもありますread -t
。
このスクリプトには、次のアプローチが含まれています。
# Start the (potentially blocking) read process in the background
(read -p && print "$REPLY" > "$Tmp") & readpid=$!
# Now start a "watchdog" process that will kill the reader after
# some time:
(
sleep 2; kill $readpid >/dev/null 2>&1 ||
{ sleep 1; kill -1 $readpid >/dev/null 2>&1; } ||
{ sleep 1; kill -9 $readpid; }
) & watchdogpid=$!
# Now wait for the reading process to terminate. It will terminate
# reliably, either because the read terminated, or because the
# "watchdog" process made it terminate.
wait $readpid
# Now stop the watchdog:
kill -9 $watchdogpid >/dev/null 2>&1
REPLY=TERMINATED # Assume the worst
[[ -s $Tmp ]] && read < "$Tmp"