Posts tagged #cli

Run and stop multiple long-running commands from Bash with a trap

by Liam Hammett · 7 minute read · #bash #laravel #cli

Sometimes when working on a project, I’ll always want to run a handful of commands at the same time, some of which may return when they’re done, others might be long-running, like watchers or services actively exposing ports.

This is something that might seem simple to do with a basic Bash script at first, but what if your script has multiple processes running side-by-side and you want to be able to stop them all at once too?

Here we’re going to take a look at how we can achieve this with Bash traps and the single-ampersand operator.

Read more…