Say I want to modify the latter of some concatenated command line options, is it possible without killing the first command?

Specifically I have compile and run scripts executed thusly:

> compile ; run

The compile is in progress (half way through two hour duration), but new information tells me I don't really want the "run" command to run anymore (it launches a lot of background processes I don't want to go clean up).

Is there a way to accomplish this adjustment or should I just be smarter about how I string together commands in the future?

  • You should probably be "smarter" and use && instead of ;. – terdon May 2 '13 at 17:03
  • To clarify, I only know that I want to cancel the run after the compile has been running a while (and I don't want to restart the compile) and I want the run to be cancelled regardless of exit code from the compile. – owenfi May 2 '13 at 17:07
  • That's the idea, when linked with && the run will not run if the compile is stopped. – terdon May 2 '13 at 17:10
  • I want the compile to finish for sure, and regardless of compile's exit code I want run not to run. I only came to find this out after an email came in an hour after my command was launched. – owenfi May 2 '13 at 17:15

Something like

compile && { test -f /path/to/dont_run || run; }

should solve your problem. touch /path/to/dont_run would prevent run from being executed. You can make this more complicated (and more convenient) by e.g. defining a shell function cond_run_cmd which does some check like that, limited to its tty (so that you can have several in parallel) or whatever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.