Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Safe-r Bash Scripting (asymmetrical-view.com)
5 points by kyleburton on Aug 9, 2009 | hide | past | favorite | 1 comment



Use "set -u" to treat unset variables as an error when substituting. Use "||" operator to handle errors. My pattern:

an_command || { error "Cannot execute an_command. Exit code: $?." return 1 }

Always wrap variables with double quotes, unless you really need to parse variable value by bash. Use arrays, when you need to pass multiple arguments. And so on.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: