bash循环并行

BaR*_*Rud 4 bash gnu-parallel

我试图并行运行这个脚本,因为每组i <= 4.在runspr.py本身平行,和多数民众赞成罚款.我想要做的是在任何实例中只运行4 i循环.

在我现在的代码中,它将运行一切.

#!bin/bash
for i in *
do 
  if [[ -d $i ]]; then
    echo "$i id dir"
    cd $i
      python3 ~/bin/runspr.py SCF &
  cd ..
  else
    echo "$i nont dir"
  fi
done
Run Code Online (Sandbox Code Playgroud)

我关注了https://www.biostars.org/p/63816/https://unix.stackexchange.com/questions/35416/four-tasks-in-parallel-how-do-i-do-that 但是无法并行地实现代码.

anu*_*ava 5

您不需要使用for循环.您可以gnu parallel这样使用find:

find . -mindepth 1 -maxdepth 1 -type d ! -print0 |
parallel -0 --jobs 4 'cd {}; python3 ~/bin/runspr.py SCF'
Run Code Online (Sandbox Code Playgroud)