If writing a lot of bash scripts, I really recommend shellcheck. It’s a linter for bash that gives a lot of good advice and points out common issues/inefficiencies and errors.
There’s plugins for most editors or you can just run it in a terminal.
I also like that it has good documentation that tells you why something might be wrong or inadvisable.
When writing BASH scripts:
.shextension isn’t necessary./usr/bin/env bashis better than/bin/bashas not everyone has their bash located in bin.set -euo pipefail. It will only cause more issues down the road.These are some of the tips I learned while learning bash.
Wait why? It’s dangerous if the script silently fails surely.
Also a cool tip
( Long Code here You want to track ) | tee -a log.txtIf writing a lot of bash scripts, I really recommend shellcheck. It’s a linter for bash that gives a lot of good advice and points out common issues/inefficiencies and errors. There’s plugins for most editors or you can just run it in a terminal. I also like that it has good documentation that tells you why something might be wrong or inadvisable.
https://github.com/koalaman/shellcheck