组合命令作为 bash 中的超时参数



我可以将超时用作:

timeout 5s sleep 6s

但是我怎样才能将更复杂的命令传递给超时呢?我尝试过以下操作,但都给了我错误:

timeout 5s sleep 6s && echo "You did not fit in timeout"
timeout 5s 'sleep 6s && echo "You did not fit in timeout"'
timeout 5s {sleep 6s && echo "You did not fit in timeout"}
timeout 5s (sleep 6s && echo "You did not fit in timeout")

看看这个:

$ timeout 5 sleep 2 && echo OK || echo "You did not fit in timeout"
OK
$ timeout 1 sleep 2 && echo OK || echo "You did not fit in timeout"
You did not fit in timeout

几乎在发布后,我就想通了:

timeout 5s sh -c 'sleep 6s && echo "You did not fit in timeout"'

有没有更好的解决方案?

相关内容

  • 没有找到相关文章

最新更新