I have a bash script that
has a for loop that iterates a lot of times and sleeps between iterations, potentially for a long time. It then
writes results to a file, then terminates.
On occasion I get the result I need before many loop iterations are complete.
On these occasions I need the script to
break out of the for loop while it is either
doing stuff, or
in such as way that it will continue with the rest of the script, after the for loop, which is writing a report file of data it's gathered so far.
I wish to use a key combination, eg CTRL+Q, to
break out of the for loop.
Script looks like this:
#!/bin/bash for (( c=0; c<=$1; c++ )) do # SOME STUFF HERE # data gathering into arrays and other commands here etc # sleep potentially for a long time sleep $2 done #WRITE REPORT OUT TO SCREEN AND FILE HERE