2

After running the following command...

$ for i in {1..10}; do sleep 3; echo $i; done

...if I wait a few seconds and hit Ctl+Z, then I get the following:

1
2
^Z
[1]+  Stopped                 sleep 3

Now if I use fg to resume the process, it resumes the sleep 3 part of the loop, but does not finish the loop:

$ fg
sleep 3
$

Is there a way to stop the process such that the loop can be continued later?

codeforester
  • 39,467
  • 16
  • 112
  • 140
reynoldsnlp
  • 1,072
  • 1
  • 18
  • 45
  • 6
    Replace `for i in {1..10}; do sleep 3; echo $i; done` with `(for i in {1..10}; do sleep 3; echo $i; done)`. See: [Bash: run one command after another, even if I suspend the first one (Ctrl-z)](https://stackoverflow.com/q/13600319/3776858) – Cyrus Jun 17 '17 at 14:26

1 Answers1

1

As other mentioned you need to start new sub-shell with (for i in {1..10}; do sleep 3; echo $i; done) You can suspend with ctrl+z. If you run jobs command, you should see the suspended jobs. Then resume it via fg or bg commands

enter image description here

Jsfiddle:http://jsfiddle.net/lakshmipathi/chccLdLt/3/

webminal.org
  • 44,948
  • 37
  • 94
  • 125