# Bash

./shell-script-template-bash.sh:

#!/usr/bin/env bash
# Tested against Bash 4.4.23(1)-release
set -eu -o pipefail

set -o noclobber    # Avoid overlay files (echo "hi" > foo)
set -o errexit      # Used to exit upon error, avoiding cascading errors
set -o pipefail     # Unveils hidden failures
set -o nounset      # Exposes unset variables

# set -o nullglob     # Non-matching globs are removed  ('*.foo' => '')
shopt -s nullglob   # Non-matching globs are removed  ('*.foo' => '')
# set -o failglob     # Non-matching globs throw errors
shopt -s failglob   # Non-matching globs throw errors
# set -o nocaseglob   # Case insensitive globs
shopt -s nocaseglob # Case insensitive globs
# set -o globstar     # Allow ** for recursive matches ('lib/**/*.rb' => 'lib/a/b/c.rb')
shopt -s globstar   # Allow ** for recursive matches ('lib/**/*.rb' => 'lib/a/b/c.rb')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# ZSH

./shell-script-template-zsh.sh:

#!/usr/bin/env zsh
set -ef -o pipefail
# set -euf -o pipefail

# For zsh
# setopt -s nullglob   # Non-matching globs are removed  ('*.foo' => '')
# setopt -s failglob   # Non-matching globs throw errors
# setopt -s nocaseglob # Case insensitive globs
# setopt -s globstar # Allow ** for recursive matches ('lib/**/*.rb' => 'lib/a/b/c.rb')
1
2
3
4
5
6
7
8
9
Last Updated: Tuesday, 4 August 2020