tags:

views:

3889

answers:

3

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
+18  A: 
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
Stefano Borini
+5  A: 

You can use semicolons to separate statements:

$ while [ 1 ]; do foo; sleep 2; done
mipadi
A: 
while $(sleep 2); do : foo; done
Two differences from the OP's script: `do : foo` does nothing (you need to leave out the ":") and `sleep` is executed before `foo` here instead of after.
Dennis Williamson