Run one command after another, even if I suspend the first one (Ctrl-z)

asmeurer picture asmeurer · Nov 28, 2012 · Viewed 67.5k times · Source

I know in bash I can run one command after another by separating them by semicolons, like

$ command1; command2

Or if I only want command2 to run only if command1 succeeds, using &&:

$ command1 && command2

This works, but if I suspend command1 using Ctrl-z, in the first case, it runs command2 immediately, and in the second case, it doesn't run it at all. How can I run commands in sequence, but still be able to suspend the first command, but not have the second run until I have restarted it (with fg) and it finishes? I'd prefer something as simple to type as possible, as I would like to do this interactively. Or maybe I just need to set an option somewhere.

By the way, what is the proper term for what Ctrl-z does?

Answer

NPE picture NPE · Nov 28, 2012

The following should do it:

(command1; command2)

Note the added parentheses.