I’ve recently been working on building my understanding of Linux and as such have been delving more into bash and bash scripts. I came across a helpful tool that will perform a static analysis of your bash/sh scripts.
Installation
If you just want to try it out without actually installing there is a website where you can paste in your shell script and get feedback.
However, in the interest of a terminal-centric workflow, we don’t want to have to keep switching back and forth between windows.
You can install shellcheck via most package managers such as apt, dnf, brew and of course pacman because I run arch btw.
pacman -S shellcheckUsing shellcheck
Then using it is straightforward. You just run the shellcheck command and pass the filepath for the script you want to check.
shellcheck my_shell_scriptEditor integration
It’s even possible to integrate shellcheck into your editor and get the suggestions directly. This isn’t something that I have explored yet though.
Why I like it?
Shellcheck provides helpful feedback quickly. It is actually a very useful learning aid. If there is an issue with your script then it will point you to a specific wiki resource that explains it.
shellcheck my_script
# OutputIn my_script line 2:lonely="unused"^----^ SC2034 (warning): lonely appears unused. Verify use (or export if used externally).
For more information: https://www.shellcheck.net/wiki/SC2034 -- lonely appears unused. Verify use...