Skip to main content
Nordlys logo, simplified northern lights aurora visualization Matt Ellis

Back to all posts

Shellcheck

Published on by Skux4life · 2 min read

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.

Install shellcheck
pacman -S shellcheck

Using shellcheck

Then using it is straightforward. You just run the shellcheck command and pass the filepath for the script you want to check.

Run shellcheck
shellcheck my_shell_script

Editor 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.

Example output
shellcheck my_script
# Output
In 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...