tra*_*veh 6 ubuntu shell-script
我知道如何在与这样的模式匹配的所有子目录中运行命令(假设我想运行gh repo sync
):
for d in ./*/ ; do (cd "$d" && gh repo sync) ; done
Run Code Online (Sandbox Code Playgroud)
并在每个目录的子shell中串行运行命令。
我想要的是并行运行所有命令,但在主脚本中等待它们全部完成。
我使用的是 Ubuntu 22.04。那可能吗?
roa*_*ima 12
在后台运行每个子 shell 命令,然后等待它们全部完成
for d in ./*/
do
( cd "$d" && gh repo sync ) &
done
wait
Run Code Online (Sandbox Code Playgroud)
l0b*_*0b0 12
GNU Parallel 在这方面做得非常出色。我已经每天使用这个结构很长一段时间了:
parallel --wd '{}' 'gh repo sync' ::: ./*/.git/..
Run Code Online (Sandbox Code Playgroud)
在我自己的系统上进行类似测试:
$ parallel --wd '{}' 'pwd' ::: ~/my\ projects/*/.git/..
/home/username/my projects/acard
/home/username/my projects/acp01
[125 more]
Run Code Online (Sandbox Code Playgroud)