1
votes

How do I use GNU Parallel to run shellcheck on all *.sh with a wrapper function?

This attempt has the correct target files, but Parallel seems to struggle with the subshell.

lint:sh() {
  local output
  targets=$(find . -name '*.sh' -exec echo {} \;)
  output=$(parallel --no-notice shellcheck ::: "$targets")
  results $? "$output"
}
2
I think you want targets to be an array. targets=($(find ...)) then pass ”${targets[@]} to GNU Parallel - Mark Setchell
find ... -exec echo {} \; seems overly verbose - try omitting -exec and everything after. - Mark Setchell
When using an array (verbose is not he current issue) mapfile -t targets < <(find . -name '*.sh' -exec echo {} \;) output=$(parallel --no-notice shellcheck ::: "${targets[@]}") i get a non-zero exit but in the subshell not, lint:sh - results is not invoked - Tom
And its it is invoking the targets rather than passing them to shellcheck - Tom
I don't think a colon is permitted in a function name, btw. - Mark Setchell

2 Answers

1
votes

Use the following approach:

lint:sh() {
  local output
  output=$(find . -name "*.sh" -print0 | parallel -q0 --no-notice shellcheck)
  ...
}
0
votes

due to different flaws in bash the safiest way may be

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

also because targets type was changed to array

output=$(parallel --no-notice shellcheck ::: "${targets[@]}")