加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 02:13:32 所属栏目:Linux 来源:网络整理
导读:这工作正常(无限循环): $while TRUE; do printf ".";done ………………………………………….. ……………………… 我试图在使用timeout命令循环时超时. 所有这些都不起作用: $timeout 5 while TRUE; do printf ".";done$timeout 5 "while TRUE; do printf
这工作正常(无限循环):

$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'

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读