Skip to content

Instantly share code, notes, and snippets.

@ppanyukov
Created July 10, 2019 09:57
Show Gist options
  • Save ppanyukov/a863f1eafe69ce318816219cba119c26 to your computer and use it in GitHub Desktop.
Save ppanyukov/a863f1eafe69ce318816219cba119c26 to your computer and use it in GitHub Desktop.
bash script template
#!/usr/bin/env bash
# Copy this entire thing at the beginning of all your bash scripts,
# this will save you a lot of trouble now and in the future.
# -e: Fail on errors
# -u: Fail on undeclared/unbound variables
set -eu
# This is the directory where this script is.
# Use this to write scripts which work in directory-independent way
# so the users can start them from whereever.
ROOT_DIR="$(cd $(dirname ${BASH_SOURCE}) && pwd)"
# The rest of your script here...
# Remember, if you invoke script directly like /tmp/foo.sh it needs
# to be marked executable like `chmod +x /tmp/foo.sh`.
# Might be better to run it with `bash /tmp/foo.sh` to avoid doing this executable thing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment