Home Syntax for a single-line Bash infinite while loop

Syntax for a single-line Bash infinite while loop

user6453
1#
user6453 Published in September 20, 2018, 12:43 pm

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 [ 1 ]
do
foo
sleep 2
done

• replace newlines with semicolons. The same works for for loops. – Tom Aug 17 '09 at 16:34
• @Tom: that doesn't always work. after the do, you must have the first command, not a semicolon – Stefano Borini Aug 17 '09 at 16:38