语法单行BASH的无限while循环 [英] Syntax for a single-line BASH infinite while loop
本文介绍了语法单行BASH的无限while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有未来与分号和/或括号的正确组合的麻烦。我想这样做,但在命令行中只有一行:
,而[1]
做
富
睡眠2
DONE
解决方案
而真实的;做富;睡眠2; DONE
顺便说一句,如果你键入它作为一个多(因为你是显示),在命令提示符下,然后调用箭头向上的历史,你会得到它在一行上,正确地打断。
$,而真正的
>做
>回声你好
>睡眠2
> DONE
你好
你好
你好
^ C
$<箭头向上>而真实的;不要回声你好;睡眠2; DONE
Having trouble coming up with the right combination of semicolons and/or braces. I'd like to do this, but as a one-liner from the command line:
while [ 1 ]
do
foo
sleep 2
done
解决方案
while true; do foo; sleep 2; done
By the way, if you type it as a multiline (as you are showing) at the command prompt and then call the history with arrow up, you will get it on a single line, correctly punctuated.
$ while true
> do
> echo "hello"
> sleep 2
> done
hello
hello
hello
^C
$ <arrow up> while true; do echo "hello"; sleep 2; done
这篇关于语法单行BASH的无限while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文