Linux Blog

Bash Continuous Loop

Filed under: Quick Linux Tutorials,Shell Script Sundays — Owen at 8:00 am on Sunday, February 15, 2015

I came across a use case for running something continuously until breaking, rather than pick a large number and a for loop (for i in `seq 1 10000`) you can use a while loop with something that returns true, my first instinct was to use while echo, but that returns a blank line in-between each iteration, which could be useful, but if you don’t want any kind of spacing or notifications you can use while true as follows:

while true; do 
echo "STUFF"; 
done;

This technique could be used with sleeps to run something every x seconds, although when you start getting into that you’d probably be better off using cron.