Try doing the Ctrl-z/fg sequence in this: "while true ; do sleep 1 ; done". Under Linux at least, you'll see that after 'fg', the loop ends :-(
Apparently C-z followed by fg is not bulletproof...
Apparently C-z followed by fg is not bulletproof...
zsh does the right thing, when you bg it back it recovers the loop as it was. Bash seems to forget about the loop and only recovers the "sleep 1", when it starts executing again it sleeps 1 and exits.
If you want to make sure it will work you should wrap it around another bash:
bash -c 'while true ; do sleep 1 ; done'
should work fine. (while true ; do sleep 1 ; done)sleep(1) is the only process that can be suspended in this command. When you "fg", the suspended sleep(1) is signaled, and resumes. And then it exits.
When you do this in a subshell (in parens), you suspend/resume the subshell in its entirety, which capture the loop construct.
Why does it work in zsh?!