如何使用 GNU Parallel 在所有带有包装函数的 *.sh 上运行 shellcheck?
此尝试具有正确的目标文件,但 Parallel 似乎与子shell 斗争。
lint:sh() {
local output
targets=$(find . -name '*.sh' -exec echo {} \;)
output=$(parallel --no-notice shellcheck ::: "$targets")
results $? "$output"
}
如何使用 GNU Parallel 在所有带有包装函数的 *.sh 上运行 shellcheck?
此尝试具有正确的目标文件,但 Parallel 似乎与子shell 斗争。
lint:sh() {
local output
targets=$(find . -name '*.sh' -exec echo {} \;)
output=$(parallel --no-notice shellcheck ::: "$targets")
results $? "$output"
}
使用以下方法:
lint:sh() {
local output
output=$(find . -name "*.sh" -print0 | parallel -q0 --no-notice shellcheck)
...
}
由于 bash 的不同缺陷,最安全的方法可能是
targets=()
while read -r -d '' file; [[ $file ]]; do
targets+=("$file");
done < <(find . -name '*.sh' -print0)
也因为targets类型更改为数组
output=$(parallel --no-notice shellcheck ::: "${targets[@]}")