I use a linter for BASH called ShellCheck, it can be installed on Debian based systmes with:
# apt-get install shellcheck
You can then invoke it simply from the command line to get feedback on your shell script. The messages are colour coded to indicate their severity: green, yellow and red:
$ shellcheck shellcheck-test.sh
In shellcheck-test.sh line 3:
read_user_input() {
^-- SC2120: read_user_input references arguments, but none are ever passed.
In shellcheck-test.sh line 5:
echo $el
^-- SC2086: Double quote to prevent globbing and word splitting.
In shellcheck-test.sh line 6:
i=1
^-- SC2034: i appears unused. Verify it or export it.
In shellcheck-test.sh line 11:
read_user_input
^-- SC2119: Use read_user_input "$@" if function's $1 should mean script's $1.
In shellcheck-test.sh line 15:
main $@
^-- SC2068: Double quote array expansions, otherwise they're like $* and break on spaces.
Emacs integration
It's easy getting on the fly linting of the BASH scripts you're working on by installing flycheck:
M-x package-install flycheck
and enable it everwhere:
(setq global-flycheck-mode t)
It will now pick up whatever linting tool you've installed for the
current mode, e.g. shellcheck
. For a list of all languages and
linting tools it supports out of the box, have a look at
this list .