For anyone wondering, this is how you launch childs in the background and kill them on ctrl+c:
#!/usr/bin/env bash
command1 &
pid[0]=$!
command2 &
pid[1]=$!
trap "kill ${pid[0]} ${pid[1]}; exit 1" INT
wait
More Related Contents:
- Command not found error in Bash variable assignment
- Why does shell ignore quoting characters in arguments passed to it through variables? [duplicate]
- How can I use a file in a command and redirect output to the same file without truncating it?
- How to check if a variable is set in Bash
- Why does a space in a variable assignment give an error in Bash? [duplicate]
- What is the preferred Bash shebang?
- Return value in a Bash function
- Shell equality operators (=, ==, -eq)
- What is a simple explanation for how pipes work in Bash?
- Indirect variable assignment in bash
- redirect COPY of stdout to log file from within bash script itself
- Shell script to delete directories older than n days
- How to recursively find the latest modified file in a directory?
- How to extract directory path from file path?
- Quick-and-dirty way to ensure only one instance of a shell script is running at a time
- What is the difference between ${var}, “$var”, and “${var}” in the Bash shell?
- What does the Bash operator
- Remove duplicate entries in a Bash script [duplicate]
- Custom Bash prompt is overwriting itself
- How to parse a CSV in a Bash script?
- How does this bash fork bomb work? [duplicate]
- Grepping a huge file (80GB) any way to speed it up?
- Launch Google Chrome from the command line with specific window coordinates
- What does “plus colon” (“+:”) mean in shell script expressions?
- How does AND and OR operators work in Bash?
- Test if a command outputs an empty string
- How to split one string into multiple variables in bash shell? [duplicate]
- How to effectively abort the execution of a Bash script from a function
- How can I check if a package is installed and install it if not?
- What is more portable? echo -e or using printf?