ShellCheck

Find bugs and pitfalls in shell scripts before you run them

About

ShellCheck reads a shell script and points out likely mistakes. Quoting bugs, non-portable constructs, and more. Each finding comes with an explanation and a suggested fix.

Install it

pkg install shellcheck

Run this inside Termux. If the package is already present, pkg will say so and do nothing.

Commands worth knowing

5 of the invocations you will actually reach for. Tap the copy button to put one on your clipboard.

shellcheck script.sh Check a script and report every issue found, with the line number and a link.
shellcheck -s bash script.sh Check a script as Bash, even if its first line names another shell.
shellcheck -S warning script.sh Report only issues at warning level or above. Style suggestions are hidden.
shellcheck -f gcc script.sh Print findings in a format many editors understand, so you can jump to each line.
shellcheck -x script.sh Follow the files a script sources, so variables defined elsewhere are understood.

Worked example

Run shellcheck script.sh and this is what you should see.

termux
$ shellcheck script.sh
In script.sh line 5:
  rm $DIR/*.tmp
     ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: rm "$DIR"/*.tmp ?

Each finding names a rule you can look up for the reasoning.

Developed by

Vidar Holen .