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!
Best Answer
You should be able to do this in the same shell you're in with the
wait
command:excerpt from Bash man page