Recursiveness – ShellCheck Wiki

See this page on GitHub


By default, shellcheck does not support a -r option. The reason for this is that there are different matching patterns for different files.

Script could have a .sh extension, no extension and have a range of shebang lines (which have their own testing format):

The solution for this problem is to use shellcheck in combination with the find or grep command.

By file extension

To check files with one of multiple extensions:

# Bash 4+
# nullglob will prevent one of the extension patterns from appearing in the arg list
# if they don't match.
# dotglob will match shell scripts in hidden directories.
shopt -s nullglob dotglob
shellcheck /path/to/scripts/**.{sh,bash,ksh,bashrc,bash_profile,bash_login,bash_logout}

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

To check files whose shebang indicate that they are sh/bash/ksh scripts:

find /path/to/scripts -type f -exec grep -Eq '^#!(.*/|.*env +)(sh|bash|ksh)' {} \; \
  | xargs shellcheck

With Docker

docker run --volume /path/to/scripts:/mnt koalaman/shellcheck-alpine sh -c "find /mnt -name '*.sh' | xargs shellcheck"

To exclude file/directory

To exclude files or directories from the search(find) results use ! -path. To exclude vendor directory for example:

find /path/to/scripts -type f \( -name '*.sh' \) ! -path '*/vendor/*' | xargs shellcheck -x -s sh

ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.