3

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?

3 Answers 3

6

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"
0
2

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

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .