Suppose there are 2 tasks t1
, t2
which can be executed in a serial way as below:
t1 ; t2
# OR
t1 && t2
Now suppose I forgot to run t2
and t1
is already running; can I add t2
to the pipeline so that it gets executed after t1
finishes?
Suppose there are 2 tasks t1
, t2
which can be executed in a serial way as below:
t1 ; t2
# OR
t1 && t2
Now suppose I forgot to run t2
and t1
is already running; can I add t2
to the pipeline so that it gets executed after t1
finishes?
Yes you can:
fg
or%
, add what you want to the list and execute it, e.g.: Sincefg
returns the return value of the job it resumed, list operators like&&
and||
work as expected:man bash
/JOB CONTROL says about the suspend character:fg
is explained inman bash
/SHELL BUILTIN COMMANDS:Further reading (aside from
man bash
) on job control:I saw this method here: https://superuser.com/questions/334272/how-to-run-a-command-after-an-already-running-existing-one-finishes
where you first do Ctrl+z to stop (suspend) the running one then you run the missed command like so:
fg && ./missed_cmd.sh
and it will run as soon as thefg
finishes.The
fg
(foreground command) will bring the suspended job online and the&&
will ensure that the missed command is only run if the first command succeeds.