I want to run a few commands, each of which doesn’t quit until Ctrl+C is pressed. Is there something I can run to run all of them at once, and Ctrl+C will quit them all? They can share the terminal output.
Specifically, I have the compass compiler, coffeescript compiler, and a custom command that watches for file changes all running watching for file changes. I don’t want to load up a terminal for each command.
This bash script is for N parallel threads. Each argument is a command.
trapwill kill all subprocesses when SIGINT is catched.wait $PID_LISTis waiting each process to complete.When all processes have completed, the program exits.
Save this script as
parallel_commandsand make it executable.This is how to use this script:
Example:
Start 4 parallel sleep and waits until “sleep 4” finishes.