ShellCheck, a utility to check your Shell scripts

shell check

As we all know, the terminal is an inseparable part of the Linux system and behind everything we do in the terminal, there is the shell, a program that interacts with the operating system itself. Every command we enter in the terminal is ultimately interpreted by the shell and then acts accordingly.

A UNIX shell is not just a command interpreter, it also serves as a programming language. Shell as a programming language provides variables, control-flow constructs, budgets, and functions.

A file that contains commands and shell codes is called a Shell Script. Therefore, you can perform various complex tasks and automation for your system using shell scripts.

Many of those who are learning bash programming and even several who are developers of it, they usually carry out some tests of codes or examples that they come to find on the net.

Although this is usually somewhat dangerous, for those experienced or who have knowledge of bash and / or Linux do not usually fall for jokes or scripts that can destroy the system or steal information.

Anyway, as we are human, we make mistakes. Obviously, writing shell scripts also makes mistakes, such as syntactic errors, typos, bad patterns, etc.

But for the novice side (generally students or curious) this is not so simple, that is why they can make use of a great utility that can help us with the analysis of these codes.

About ShellCheck

ShellCheck is a static analysis tool that displays warnings and suggestions for bad code in bash / sh shell scripts.

It can be used in various ways: from the web by pasting your shell script into an online editor or alternatively, it can be to install it on your system and run it from the terminal, integrate it with your text editor, as well as your compilation or suites test.

There are three things that ShellCheck does primarily:

  • Point out and explain typical beginner syntax problems that cause a shell to give cryptic error messages.
  • Point out and explain typical intermediate-level semantic problems that cause a shell to behave strangely.
  • It also points out subtle warnings, which can cause an otherwise working advanced script to fail in future circumstances.

shell check

How to install ShellCheck on Linux?

If you are interested in being able to obtain this great utility, you just have to open a terminal on your system and type one of the following commands, according to the Linux distribution you are using.

Users of Debian, Ubuntu and any other distribution derived from these, they only have to type in the terminal the following command:

sudo apt-get install shellcheck

If they are users of RHEL, CentOS, Fedora or any distribution derived from these, can install with:

sudo dnf install shellcheck

For users of Arch Linux, Antergos, Manjaro and derivatives of Arch Linux, install the utility with:

sudo pacman -S shellcheck

While for those who are openSUSE users, the installation is done with:

sudo zypper in shellcheck

Si use Atom text editor, you can also use ShellCheck within your editor window on the go. They just have to install the atom packages needed for ShellCheck:

apm install linter linter-shellcheck

ShellCheck tIt also supports other editors, such as: Vim, Emacs, Sublime, etc. You can find a complete list In the following link.  

Basic use of ShellCheck

After installing the necessary packages for ShellCheck on your system, They can use them from their terminal, they just have to write the following command:

shellcheck / path / to / file

Where they just have to put the path with the filename of their shell script.

Using ShellCheck online

Also, you can use ShellCheck online without installing anything on your system, so you only have to use your preferred web browser and go to to the following link.

Here they just have to copy the codes from their shell script and it will show the ShellCheck output.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   neomadrid70 said

    Very interesting article
    Thank you very much