Using ShellCheck to write better shell scripts
Introduction Over the course of the last couple of years we’ve written numerous posts on understanding and experimenting with different aspects of bash shell scripting. In this article we’ll focus on how we could improve our shell scripts and write better and more maintainable code using a tool named ShellCheck. ShellCheck is a static analysis tool written in hasekell programming language and is meant to analyse shell scripts written to use the bash and sh shells. ShellCheck is aimed at providing the following set of features: To point out and clarify typical beginner’s syntax issues that cause a shell to give cryptic error messages. To point out and clarify typical intermediate level semantic problems that cause a shell to behave strangely and counter-intuitively. To point out subtle caveats, corner cases and pitfalls that may cause an advanced user’s otherwise working script to fail under future circumstances. Installing ShellCheck Installing ShellCheck is a failry straightforward process. On RHEL based systems, we first need to ensure that the EPEL repository is available before we install ShellCheck. [root@linuxnix ~]# yum install epel-release -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.usonyx.net * epel: mirrors.aliyun.com * extras: centos.usonyx.net * nux-dextop: mirror.li.nux.ro * updates: centos.usonyx.net epel/x86_64/primary | 3.5 MB 00:00:00 epel 12619/12619 Package epel-release-7-11.noarch already installed and latest version Nothing to do [root@linuxnix ~]# Now that we have confirmed that...
Read More