I have cmd2
that needs to follow after cmd1
completes. I need to pause cmd1
sometimes.
I type in
$ cmd1 && cmd2
and then press Ctrl+Z (Stop)
to stop cmd1
. Now, cmd1
is paused but when I resume, it does not start cmd2
after completion of cmd1
.
I type in
$ cmd1 ; cmd2
and then I press Ctrl+Z (Stop)
to stop cmd1
. Now cmd1
is paused but it immediately starts cmd2
. However, I wish to start cmd2
only after cmd1
finishes.
I did some research and someone suggested an elegant way in zsh
but I wonder if there is an elegant way of doing it in bash
.
Run it in a 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With