Syntax for a single-line Bash infinite while loop

前端 未结 13 1419
长情又很酷
长情又很酷 2020-11-29 14:18

I am 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 [         


        
13条回答
  •  旧时难觅i
    2020-11-29 15:02

    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
    $  while true; do    echo "hello";    sleep 2; done
    

提交回复
热议问题