There are a number of ways to loop forever (or until you decide to stop) on Linux and you can do this on the command line or within scripts.\nThe for and while commands make the job quite easy. There are only a few things to keep in mind with respect to syntax and tactics.\n\nUsing while\nOne of the easiest forever-loops involves using the while command followed by the condition "true". You don\u2019t have to bother with logic like while [ 1 -eq 1 ] or similar tests. The while true test means the loop will run until you stop it with CTRL-C, close the terminal window or log out. Here's an example:\n$ while true\n> do\n> echo Keep running\n> sleep 3\n> done\nKeep running \nKeep running \nKeep running \n^C\n\nYou can also do the same thing with while :. The key here is that the\u00a0: always yields success so, like while true, this test doesn\u2019t ever fail and the loop just keeps running.\n$ while :\n> do\n> echo Keep running\n> sleep 3\n> done\nKeep running\nKeep running\n^C\n\nIf you\u2019ve inserted an infinite loop into a script and want to remind the person who is using it how to exit the script, you can always add a hint using the echo command:\nwhile :\ndo\n\techo Keep running\n\techo "Press CTRL+C to exit"\n\tsleep 1\ndone\n\nUsing for\nThe for command also provides an easy way to loop forever. While not quite as obvious as while true, the syntax is reasonably straightforward. You just replace the parameters in a bounded loop that would generally look something like this "start with c equal to 1 and increment it until reaches 5" specification:\n$ for (( c=1; c do\n> echo Keep running\n> echo \u201cPress CTRL+C to exit\u201d\n> sleep 2\n> done\nKeep your spirits up\nKeep your spirits up\nKeep your spirits up\n\nWhy loop forever?\nIn real life, you\u2019re not ever going to want to loop forever, but running until it\u2019s time to go home, the work is done or you run into a problem is not at all unusual. Any loop that is constructed as an infinite loop can also be set up to be exited depending on various circumstances.\nThis script would keep processing data until 5 p.m. or the first time it checks the time after 5 p.m.:\n#!\/bin\/bash\n\nwhile true\ndo\n if [ `date +%H` -ge 17 ]; then\n exit\t# exit script\n fi\n echo keep running\n ~\/bin\/process_data # do some work\ndone\n\nIf you want to exit the loop instead of exiting the script, use a break command instead of an exit.\n#!\/bin\/bash\n\nwhile true\ndo\n if [ `date +%H` -ge 17 ]; then\n break\t# exit loop\n fi\n echo keep running\n ~\/bin\/process_data\ndone\n\u2026 run other commands here \u2026\n\nWrap-Up\nLooping forever is easy. Specifying the conditions under which you want to stop looping takes a little extra effort.