Skip to content

Instantly share code, notes, and snippets.

@sheharyarn
Created October 29, 2016 21:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sheharyarn/5240ecbe7b3b6f959782811a7c3ac818 to your computer and use it in GitHub Desktop.
Save sheharyarn/5240ecbe7b3b6f959782811a7c3ac818 to your computer and use it in GitHub Desktop.
Bash Script Boilerplate code
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
# Set magic variables for current file & dir
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app
arg1="${1:-}"
## Taken from:
## http://kvz.io/blog/2013/11/21/bash-best-practices/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment