How to run a Linux command in an unlimited loop

Here is how to run any command line in a loop that will repeat endlessly. Before you begin it is best to test the command line you wish to repeat manually once to make sure it is working as expected.

The command will need to be surrounded in the following BASH commands, for this example the command line we wish to repeat is echo 'hello world'.

while true; do echo 'hello world'; done

The while loop with iterate only when the command inside it exits or detaches from the terminal. The above code could also be placed inside a BASH script for later use.

Last updated: 22/09/2010