I want to run all scripts in a directory at the same time.I know that I can get a list of all the scripts and execute the first one in a directory with `ls ./*.sh`, but I can't seem to get all of them to run.I also tried brace expansion {./*.sh; } but that also ran only the first script.After I figure out how to run all of the them I want to run all of them in the background.I know that I can probably do this with a for loop, but I was hoping there is a simple one liner using globbing or brace expansion that will get the job done simply.How can I do this?
Run all scripts in a folder in background
bash;background process
for script in ./*.sh; do $script & donewaitOr to limit the number of concurrent invocations, with GNU xargs:xargs -n1 -P5 -r0a <(printf '%s\0' ./*.sh) env(beware it assumes script names don't contain = characters).Or with zsh:autoload zargs # best in ~/.zshrczargs -n1 -P5 ./*.sh -- command(here at most 5 at a time).Beware that if those scripts produce any output they could end-up being badly interleaved. GNU parallel addresses that by storing the output of each command in a separate temporary file and outputting them in order:parallel -j0 exec ::: ./*.sh(-j0 to run all of them in parallel, remove to limit to the number of CPU cores, or specify the number yourself).