Sample Bash scripts that follow best practices learnt from a variety of sources.
These are some good resources with tips on how to write good-quality shell scripts:
- Shell Scripts Matter, proposes a template that you can use for all your scripts.
- Writing robust Bash shell scripts is another detailed article about safety measurements in Bash scripts.
- Common shell script mistakes completes the pack with even more recommendations.
It is wise to follow the recommendations of more experienced players, because they have already fought some battles that you still haven't even anticipated:
I also like a couple of pages with examples and description of common errors that Bash programmers make:
Last but not least, always use this tool to verify your scripts: ShellCheck. It can be installed as a plugin in lots of text editors and IDEs.
Happy coding!