这工作正常(无限循环):
$ while TRUE; do printf ".";done
...................................................... ……………………
我在尝试着timeout this while loop
与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'
--
确保以下参数将被视为非选项。和''
有助于通过"
没有不必要的逃避
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)