How to pause and resume a sequence of commands in Bash?

I have cmd2 that should follow after cmd1 completes. I sometimes need to pause cmd1 .

When i type

 $ cmd1 && cmd2 

and then press Ctrl+Z (Stop) to stop cmd1 . Now cmd1 pauses, but when I resume it, it does not start cmd2 after cmd1 completes.

When i type

 $ cmd1 ; cmd2 

and then press Ctrl+Z (Stop) to stop cmd1 . Now cmd1 pauses, but cmd2 starts right cmd2 , and I want to start cmd2 only after cmd1 completes.

I did some research and someone suggested an elegant way in zsh , but I am wondering if there is an elegant way to do this in bash .

+5
source share
1 answer

Run it in the subshell:

 (cmd1 && cmd2) 

Example:

 $ (sleep 5 && echo 1) # started the command chain ^Z [1]+ Stopped ( sleep 5 && echo 1 ) # stopped before `sleep 5` finished $ fg # resumed ( sleep 5 && echo 1 ) 1 # `sleep 5` finished and `echo 1` ran 
+9
source

Source: https://habr.com/ru/post/1262970/


All Articles