Shell Scripts

Advice from sharats:

Use .sh file extension.

Use long options where possible.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env bash

set -o errexit # Exit script on error
set -o nounset # Error accessing an unset variable
               # use "${VARNAME-}" for explicit optional vars
set -o pipefail # fail pipeline if any piped commands fail

# Enable debug mode via TRACE=1 ./script.sh
if  "${TRACE-0}" == "1" ; then
  set -o xtrace
fi

# If appropriate, switch to script's path before starting work
# cd "$(dirname "$0")"

main() {
    echo do awesome stuff
}

main "$@"

About

Avatar of Author

Jamie Macey is a senior software engineer with over 15 years experience in the Ruby and Rails ecosystems, largely on the back-end.

Husband, father, gamer, and all-around geek. Ask about my latest 3d print, or toy software project.