Shellcheck is a handy tool for working with bash scripts. It does a nice job of doing a sanity check of bash script against a set of rules and is simple to use. As a quick example, consider this very simple script:
#!/bin/bash
A="some value"
echo $A
echo "${A}"
echo "${B}"
This script will do what you think it should but has a few problems. Running shellcheck on this script produces some simple output with suggestions to improve the script:
In ./my_script.sh line 9:
echo $A
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$A"
For more information:
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
It’s a great way to evaluate and improve bash scripting. In conjunction with bash strict mode, shellcheck can go a long way towards making your bash scripting more robust.