Most shells provide functions like && and ; to chain the execution of commands in certain ways. But what if a command is already running, can I still somehow add another command to be executed depending on the result of the first one?
Say I ran
$ /bin/myprog
some output...
but I really wanted /bin/myprog && /usr/bin/mycleanup. I can't kill myprog and restart everything because too much time would be lost. I can Ctrl+Z it and fg/bg if necessary. Does this allow me to chain in another command?
I'm mostly interested in bash, but answers for all common shells are welcome!
%,%1and$!. It is important to supply the PID or the second command will always run. – BillThor Nov 13 '13 at 01:06waitwill fail to provide the desired result. It is common to use the short forms as they are less prone to typos. – BillThor Nov 13 '13 at 01:18