bash

Preferred Bash Shebang

#!/usr/bin/env bash

env runs a program in a modified environment, the command in this case being the first copy of bash found within ${PATH}.

source

Location of Bash Script

SCRIPT_DIR="$( cd -P -- "$( dirname -- "$(readlink -f "${BASH_SOURCE[0]}")" )" >/dev/null 2>&1 && pwd )"

source

Bash Strict Mode

#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

source

Bash Exit Traps for Cleanup

At the start of your file set up a trap with a cleanup function that should be run.

#!/usr/bin/env bash

function finish {
  # cleanup
}
trap finish EXIT

source