Fix quoting of find command and use xargs instead of a while loop, which preserves the exit status.

Michael Diamond
2020-01-20 23:03:11 -08:00
parent be5f0ca2b3
commit 40fc376596

@@ -23,11 +23,8 @@ shopt -s nullglob dotglob
shellcheck /path/to/scripts/**.{sh,bash,ksh,bashrc,bash_profile,bash_login,bash_logout}
# POSIX
find /path/to/scripts -type f \( -name "*.sh" -o -name "*.bash" -o -name "*.ksh" -o -name "*.bashrc" -o -name "*.bash_profile" -o -name "*.bash_login" -o -name "*.bash_logout" \) -print |
while IFS="" read -r file
do
shellcheck "$file"
done
find /path/to/scripts -type f \( -name '*.sh' -o -name '*.bash' -o -name '*.ksh' -o -name '*.bashrc' -o -name '*.bash_profile' -o -name '*.bash_login' -o -name '*.bash_logout' \) \
| xargs shellcheck
```
## By shebang
@@ -36,9 +33,5 @@ To check files whose shebang indicate that they are sh/bash/ksh scripts:
```
# POSIX
find /path/to/scripts -type f -exec grep -Eq '^#!(.*/|.*env +)(sh|bash|ksh)' {} \; -print |
while IFS="" read -r file
do
shellcheck "$file"
done
find /path/to/scripts -type f -exec grep -Eq '^#!(.*/|.*env +)(sh|bash|ksh)' {} \; | xargs shellcheck
```