At an interactive bash prompt, run a 'for' loop: % for i in a b c; do echo $i; sleep 10; done
Then interrupt this with Ctrl-Z. The process interrupted is just whichever sleep process was running at the time. You can then resume it with 'fg' but the loop does not continue. I understand that job control applies to processes and that bash does not create a new process to run a 'for' loop. You can force it to do so: % (for i in a b c; do echo $i; sleep 10; done) Now job control does something more sensible; the whole loop can be paused, put into the background or the foreground. But if you didn't have the foresight to put () around your command, you are stuck if you later decide you want to put it in the background. Is there something bash could do to be more user-friendly here? Could job control be made to apply to 'for' and 'while' loops, even if they were run without forking a separate process? After all, you can fork() at any time, so perhaps a new child process could be created when needed for the purpose of putting the loop in the background. Failing that, it should at least be possible to interrupt a 'for' loop with Ctrl-Z, then 'fg' and have it continue where it left off. If putting it into the background is not practical then 'bg' can give an error message. Backgrounding or foregrounding just one individual command, and then abandoning the rest of the loop somehow, is surely never the desired behaviour. -- Ed Avis <e...@waniasset.com>