Skip to content
Michael Diamond edited this page Jan 21, 2020 · 14 revisions

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):

  • #!/bin/bash
  • #!/bin/sh
  • #!/usr/bin/env bash
  • #!/usr/bin/env sh
  • etc...

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

By 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}

# 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' \) \
  | xargs shellcheck

By shebang

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)' {} \; | xargs shellcheck

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally