gpt4 book ai didi

linux - 运行文件夹中的所有 shell 脚本

转载 作者:IT王子 更新时间:2023-10-29 00:23:20 27 4
gpt4 key购买 nike

我在一个文件夹中有许多 .sh 脚本,我想一个接一个地运行它们。单个脚本可以执行为:

bash wget-some_long_number.sh -H

假设我的目录是/dat/dat1/files

如何依次运行 bash wget-some_long_number.sh -H

我理解这些行中的某些内容应该有效:

for i in *.sh;...do ....;完成

最佳答案

使用这个:

for f in *.sh; do
bash "$f"
done

如果你想在脚本失败时停止整个执行:

for f in *.sh; do
bash "$f" || break # execute successfully or break
# Or more explicitly: if this execution fails, then stop the `for`:
# if ! bash "$f"; then break; fi
done

你想运行它,例如,x1.sh, x2.sh, ..., x10.sh:

for i in `seq 1 10`; do
bash "x$i.sh"
done

保留失败脚本的退出代码(响应@VespaQQ):

#!/bin/bash
set -e
for f in *.sh; do
bash "$f"
done

关于linux - 运行文件夹中的所有 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41079143/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com