For Unix-based systems, you can use the command &
:
command1 & command2 & command3 &...
If you want more control over each command, you can use xargs
:
echo -e "command1\ncommand2\ncommand3" | xargs -P 3 -I {} sh -c "{}"
xargs takes input (lines of text) and passes each line as arguments to the specified command.
-P 3 specifies the number of parallel processes to run. Here, it will run up to 3 commands at the same time.
-I {} allows xargs to substitute {} with each line from the input. So each of the commands (sleep 5, sleep 10, echo Done!) will replace {} in the following command.
sh -c "{}" runs a shell (sh) command, where {} will be replaced by each of the commands from the input.
sh -c allows the shell to execute the command passed as a string argument.
If you need more flexibility, I suggest looking into GNU's parallel:
parallel ::: "command1" "command2" "command3"
In Windows/Powershell, you can use Start-Job:
$command1Job = Start-Job -ScriptBlock { command1 }
$command2Job = Start-Job -ScriptBlock { command2 }
To check the status of the jobs:
Get-Job -Id $command1Job
To get the output from a job:
Receive-Job -Id $command1Job
Also, you can use Windows Subsystem for Linux (WSL):
wsl command1 & command2 & command3 & ...