bash ctrl-z to send a for loop in background, only the currently run command is resumed when bg
2
votes
0
answers
57
views
poc:
$ for i in $( seq 1 10 ); do echo "begin $i"; sleep 4 ; echo " end $i" ; done
begin 1
end 1
begin 2
end 2
begin 3
## after 1 second, I : ctrl-z
^Z
+ Stopped sleep 4
$ fg # wait or no wait : same result
sleep 4
$ # the loop wasn't continued.
I notice: when pressing ctrl-z : only the currently running command (sleep) is shown as being sent in the background? What happens to the surrounding loop? and how could I have the whole for loop suspended and continued? with set -o settings? or do I need to create a script and have it sent to background? or just surround it with { } or ( ) ?
Asked by Olivier Dulac
(6580 rep)
Feb 20, 2025, 10:19 AM
Last activity: Feb 20, 2025, 10:44 AM
Last activity: Feb 20, 2025, 10:44 AM