Shell scripts are an important part of Linux systems. Most of the daily jobs and general jobs are done with shell scripts. The ShellCheck is a static analysis tool created to analyze the provided shellcode and give suggestions for better shell scripts and show warnings for some errors. The ShellCheck can be installed into all major Linux distributions where the installation is described below. The ShellCheck also provided as a web application which is also described below.
The ShellCheck is an open-source and active project which is developed via GitHub. The developed page can be accessed via https://github.com/koalaman/shellcheck . It is currently licensed with the GPLv3.
ShellCheck can be installed for all major Linux distributions and even compiled from the source code.
Ubuntu, Debian, Mint, Kali:
$ sudo apt install shellcheck
$ sudo yum -y install epel-release $ sudo yum install ShellCheck
$ sudo dnf install ShellCheck
$ sudo zypper in ShellCheck
$ brew install shellcheck
$ port install shellcheck
What Is Checked with ShellCheck?
The SchellCheck tool checks the following topics in general to provide suggestions and warnings.
- Misused Commands
- Common Novice Mistakes
- Data and Typing Errors
Check Shell Script with ShellCheck Command Line
After installation of ShellCheck, it can be used from the terminal or command line easily by just providing the shell script file. In the following example, we will check the shell script file named gettext.sh which is located under the /bin directory.
$ shellcheck /bin/gettext.sh
It works very fast where completed in a second even for larger script files. It outputs colored warnings and suggestions about the script file. First, the case line printed, and then suggestions and warnings are printed. The suggestions are printed as green and warnings are printed as orange. Also, line number information about the case is provided too.
ShellCheck Web Application
The Apply fixes button can be used to apply suggestions and warnings into the shell script easily.