Bash Error Handling
Other tips I've found after a year or two of using Bash for many things it shouldn't be used for:<p>- Use shellcheck (static analysis/linter) <a href="https://www.shellcheck.net/" rel="nofollow">https://www.shellcheck.net/</a><p>- Use shunit2 (unit tests) <a href="https://github.com/kward/shunit2" rel="nofollow">https://github.com/kward/shunit2</a><p>- Use 'local' or 'readonly' to annotate your variables<p>- Trap ctrl+c to gracefully exit (details here <a href="https://www.tothenew.com/blog/foolproof-your-bash-script-some-best-practices/" rel="nofollow">https://www.tothenew.com/blog/foolproof-your-bash-script-som...</a>)<p>- Stick to long-form options for readability (--delete over -d for example)<p>- #!/usr/bin/env > #!/bin/bash for portability<p>- Consider setting variable values in a file and importing it at the top of your script to improve refactoring<p>- You will eventually forget how your scripts work - seriously consider if Bash is your best option for anything that needs to last a while!