Skip to content

Instantly share code, notes, and snippets.

@tamalsaha
Last active June 27, 2020 10:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tamalsaha/dec0c373b7142092ba2d1435c1e322f8 to your computer and use it in GitHub Desktop.
Bash script template
#!/bin/bash
set -eou pipefail
SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/../..) # adjust as needed to go to root directory
SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
pushd $SCRIPT_ROOT
# http://redsymbol.net/articles/bash-exit-traps/
function cleanup() {
popd
}
trap cleanup EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment