bg / fg inside a command line loop

前端 未结 1 1852
情话喂你
情话喂你 2020-12-18 04:50

ctrl-z (^z) acts in ways I do not understand when done inside a loop executed from a terminal.

Say I type

for ii in {0..100}; do echo $ii; sleep 1; d         


        
相关标签:
1条回答
  • 2020-12-18 05:08

    You cannot suspend execution of the current shell. When you run your loop from the command line, it is executing in your current login shell/terminal. When you press [ctrl+z] you are telling the shell to suspend the current active process. Your loop is simply a counter in the current shell, the process being executed is sleep. Suspend only operates on sleep.

    When you backgroud a process or execute it in a subshell (roughly equivalent), you can suspend that separate process in total.

    0 讨论(0)
提交回复
热议问题