Hacker Newsnew | past | comments | ask | show | jobs | submit | rjacksonm1's favoriteslogin

Other tips I've found after a year or two of using Bash for many things it shouldn't be used for:

- Use shellcheck (static analysis/linter) https://www.shellcheck.net/

- Use shunit2 (unit tests) https://github.com/kward/shunit2

- Use 'local' or 'readonly' to annotate your variables

- Trap ctrl+c to gracefully exit (details here https://www.tothenew.com/blog/foolproof-your-bash-script-som...)

- Stick to long-form options for readability (--delete over -d for example)

- #!/usr/bin/env > #!/bin/bash for portability

- Consider setting variable values in a file and importing it at the top of your script to improve refactoring

- You will eventually forget how your scripts work - seriously consider if Bash is your best option for anything that needs to last a while!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: