在Linux shell脚本中计时一段时间

在Linux shell脚本中计时一段时间,第1张

概述这工作正常(无限循环): $while TRUE; do printf ".";done ………………………………………….. ……………………… 我试图在使用timeout命令循环时超时. 所有这些都不起作用: $timeout 5 while TRUE; do printf ".";done$timeout 5 "while TRUE; do printf ".";done"$timeou 这工作正常(无限循环):

$while TRUE; do printf ".";done

………………………………………….. ………………………

我试图在使用timeout命令循环时超时.
所有这些都不起作用:

$timeout 5 while TRUE; do printf ".";done$timeout 5 "while TRUE; do printf ".";done"$timeout 5 "while TRUE; do printf \".\";done"$timeout 5 $(while TRUE; do printf ".";done)$timeout 5 $('while TRUE; do printf ".";done')

什么是正确的方法(如果存在)?

解决方法 我认为你的问题的解决方案是执行另一个shell实例并将适当的命令传递给它.
根据bash手册:

-c        If the -c option is present,then commands are read from the first non-option argument command_string.

因此,我的解决方案将是这样的:

timeout 5 bash -c -- 'while true; do printf ".";done'

– 确保将以下参数视为非选项.并且“帮助传递”而没有不必要的逃避

总结

以上是内存溢出为你收集整理的在Linux shell脚本计时一段时间全部内容,希望文章能够帮你解决在Linux shell脚本中计时一段时间所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1032459.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存