1
0
mirror of https://github.com/koalaman/shellcheck.git synced 2025-03-12 12:35:25 -07:00

Added POSIX compatible options without shellcheck warnings

Vidar Holen 2019-03-17 19:00:55 -07:00
parent ba2d0b5128
commit b501ea60b5

@ -10,36 +10,32 @@ Script could have a `.sh` extension, no extension and have a range of shebang li
The solution for this problem is to use `shellcheck` in combination with the `find` or `grep` command.
## Without exit code
## By extension
If you're not interested in the exit code of the `shellcheck` command, you can use (a variation) of one of the following commands:
To check files with one of multiple extensions:
```
# Scan a complete folder (recursively)
find path/to/scripts -type f -exec "shellcheck" "--format=gcc" {} \;
# Bash 4+
shopt -s globstar nullglob
shellcheck /path/to/scripts/**/*.{sh,bash,ksh}
# Scan a complete folder (recursively) for .sh files
find path/to/scripts -type f -name "*.sh" -exec "shellcheck" "--format=gcc" {} \;
# POSIX
find /path/to/scripts -type f \( -name "*.sh" -o -name "*.bash" -o -name "*.ksh" \) -print |
while IFS="" read -r file
do
shellcheck "$file"
done
```
## With exit code
## By shebang
If you want to use `shellcheck` in some kind of testing pipeline, you want to know the exit code of the command.
In this case you can test every matched file individually:
To check files whose shebang indicate that they are sh/bash/ksh scripts:
```
# Scan a complete folder (recursively)
for file in $(find path/to/scripts -type f); do shellcheck --format=gcc $file; done;
# Scan a complete folder (recursively) for .sh files
for file in $(find path/to/scripts -type f -name "*.sh"); do shellcheck --format=gcc $file; done;
```
## Finding files to test
Since not all scripts have a `.sh` extension, you could use the shebang line of files to determine if they need to be tested (and with which format):
```
for file in $(grep -IRl "#\!\(/usr/bin/env \|/bin/\)sh" --exclude-dir "var" --exclude "*.txt"); do shellcheck --format=gcc --shell=sh $file; done;
# POSIX
find /path/to/scripts -type f -exec grep -Eq '^#!(.*/|.*env +)(sh|bash|ksh)' {} \; -print |
while IFS="" read -r file
do
shellcheck "$file"
done
```