How do I suspend and resume a sequence of commands in Bash?

后端 未结 1 1475
别跟我提以往
别跟我提以往 2021-01-19 03:21

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

I type in

$ cmd1 &         


        
相关标签:
1条回答
  • 2021-01-19 04:03

    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
    
    0 讨论(0)
提交回复
热议问题