From the previous question it seems I failed to understand how &&
and ^Z
interact properly:
$ command1 && command2 && command3
Running command1 ...
Running command2 ...^Z
[1]+ Stopped
$ fg && command4
Running command3
Running command4
, which I thought can be used to "append" the chain after it started, seemed to work only because of command3
was the last command; and stopping it on command2
, for example, whould have provided different result (command3
whould have been ignored).
How do I suspend the &&
chain gracefully, without cancelling the rest of the commands? I want also the exit code to be preserved if it is needed for further logic in the command line.
If I know that I may want to suspend the chain in advance, I can start it like that: ( command1 && command2 && command3 )
, so it whould be gracefully suspendable. Buw how do I do it when it is started plainly?
If the commands don't provide output (unlike in example above), should not be run twice or out of order then the only way I can think up is pressing ^Z
, analysing what was stopped, then manually constructing fd && the_rest_of_commands
, which is inconvenient and error-prone.