My 5 Rules for Writing Bash Scripts

  1. Don't use Bash.
  2. Put quotes around all variables: echo "$FOO"
  3. Don't use Bash.
  4. Put spaces between everything except assignments: FOO="bar"; if [[ -n "$FOO" ]]; then echo "$FOO"; fi
  5. Don't use Bash.

1 comment:

  1. I'd append that to use {} around variables and always use quotes: "${FOO}"

    Also: At the top of your script, always put:
    set -eu

    -e means stop the script on error.
    -u means its an error to use an undefined variable.