Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell脚本(bash/ksh):读取变量需要20秒_Bash_Unix_Ksh_Solaris 10_Shell - Fatal编程技术网

Shell脚本(bash/ksh):读取变量需要20秒

Shell脚本(bash/ksh):读取变量需要20秒,bash,unix,ksh,solaris-10,shell,Bash,Unix,Ksh,Solaris 10,Shell,我需要等待输入20秒,然后myscript将继续执行。 我尝试过使用read-t20var,但是这只适用于bash。我正在Solaris 10上使用ksh 有人能帮我吗 编辑:20秒只是一个例子。让我们假设它需要等待1小时。但是这个家伙可以或不可以在电脑前面写输入,他不需要等待1小时来输入输入,但是如果他不在电脑前面,那么shell应该在等待一段时间后继续执行 谢谢 看看第三篇文章中的答案。来源: TMOUT 如果设置为大于零的值,则如果在发出PS1提示后的规定秒数内未输入命令,则shell将终

我需要等待输入20秒,然后myscript将继续执行。
我尝试过使用
read-t20var
,但是这只适用于bash。我正在Solaris 10上使用ksh

有人能帮我吗


编辑:20秒只是一个例子。让我们假设它需要等待1小时。但是这个家伙可以或不可以在电脑前面写输入,他不需要等待1小时来输入输入,但是如果他不在电脑前面,那么shell应该在等待一段时间后继续执行

谢谢

看看第三篇文章中的答案。

来源:

TMOUT
如果设置为大于零的值,则如果在发出PS1提示后的规定秒数内未输入命令,则shell将终止。可以使用此值的最大界限编译shell,该界限不能超过

我不确定这是否适用于Solaris上的
ksh
中的
read
。它确实与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"
#在后台启动(可能阻塞)读取进程
(read-p&打印“$REPLY”>“$Tmp”)&readpid=$!
#现在开始一个“看门狗”进程,它将在之后杀死阅读器
#有时:
(
睡眠2;杀死$readpid>/dev/null 2>&1||
{sleep 1;kill-1$readpid>/dev/null 2>&1;}||
{sleep 1;kill-9$readpid;}
)&watchdogpid=$!
#现在等待读取过程结束。它将终止
#可靠地,或者因为读取终止,或者因为
#“看门狗”进程使其终止。
等等$readpid
#现在停止看门狗:
kill-9$watchdogpid>/dev/null 2>&1
答复=终止#假设最坏情况
[[-s$Tmp]]&&read<“$Tmp”

睡眠20&&read${variable}
20秒只是一个例子。让我们假设它需要等待1小时。但是这个人在电脑前面写输入,他不需要等1个小时。。。。明白了吗?谢谢,伙计,成功了。我在想。。。既然我们使用的是ksh,那么有没有办法用coproccess做到这一点呢?第三篇文章有
read-t
,OP无法使用。除非你不计算这个链接上的问题,否则第三个答案不是解决方案。这种混淆是首选在答案中包含链接信息的原因之一。TMOUT用于交互式会话,因此在发出PS1提示符后显示为
。它不会在短时间内做任何事情script@Daenyth:它在我尝试过的测试脚本中工作(但如果超时,它会使终端处于
-echo
状态,我必须进行重置)。