up vote 1 down vote favorite
share [g+] share [fb]

Tried:

while true; do date; sleep 1; done

Got:

Thu Aug 27 17:33:24 IDT 2009
Thu Aug 27 17:33:25 IDT 2009
Thu Aug 27 17:33:26 IDT 2009
...

But:

nohup while true; do date; sleep 1; done

Got me:

bash: syntax error near unexpected token `do'

Any ideas why?

link|improve this question

78% accept rate
feedback

3 Answers

up vote 3 down vote accepted

If you REALLY wanted to do it all on the command line without making a script, do this:

nohup bash -c "while true; do date; sleep 1; done"
link|improve this answer
+1 & correct, Short and to the point. thanks! – Adam Matan Aug 27 '09 at 15:16
feedback

nohup takes a command, "while" is not a command, it is a shell builtin.

link|improve this answer
feedback

while is actually a command that is built into bash, not a separate executable, so nohup can't run it. If you want to do this, you'll need to put your commands into a file and then use nohup to run that file.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.