Home Syntax for a single-line Bash infinite while loop
Reply: 0

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
share|improve this question
  • 4
    replace newlines with semicolons. The same works for for loops. – Tom Aug 17 '09 at 16:34
  • 20
    @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

11 Answers 11

active oldest votes
up vote 925 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.545325 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO