1

如何使用 GNU Parallel 在所有带有包装函数的 *.sh 上运行 shellcheck?

此尝试具有正确的目标文件,但 Parallel 似乎与子shell 斗争。

lint:sh() {
  local output
  targets=$(find . -name '*.sh' -exec echo {} \;)
  output=$(parallel --no-notice shellcheck ::: "$targets")
  results $? "$output"
}
4

2 回答 2

1

使用以下方法:

lint:sh() {
  local output
  output=$(find . -name "*.sh" -print0 | parallel -q0 --no-notice shellcheck)
  ...
}
于 2018-06-26T09:07:41.933 回答
0

由于 bash 的不同缺陷,最安全的方法可能是

targets=()
while read -r -d '' file; [[ $file ]]; do
    targets+=("$file");
done < <(find . -name '*.sh' -print0)

也因为targets类型更改为数组

output=$(parallel --no-notice shellcheck ::: "${targets[@]}")
于 2018-06-26T07:43:24.150 回答