- Don't avoid bashisms unless you know bash will be unavailable
- Use
#!/bin/bash
rather than#!/bin/sh
- If you are going to try to avoid bash, you must test on a system that does not have bash
- Use
- Always include a shebang
#!
- Handle errors
- Use
set -eu
(errexit
&nounset
)
- Use
- Sould be idemponent if read via
source
- Use subshells to avoid leaking unintended variables into the parent scope
- Only define variables and functions
- Don't run functions or commands that modify the system or environment
- Namespace variables and functions
- Mark internal variables and functions
- Beginning a variable or function with an underscore is a common indicator of internal functionality
- Beginning a variable or function with an underscore does not enforce internal-only
- Related functionality should be placed in a single script and behave differently according to the name called
- Having multiple symlinks to the same script is a convenient way to optionally avoid specifying functionality via argument
Created
December 2, 2019 19:46
-
-
Save RichardBronosky/4dd229c9df4dd2d6b9e9337bade0c2f2 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment