Created
July 10, 2019 09:57
-
-
Save ppanyukov/a863f1eafe69ce318816219cba119c26 to your computer and use it in GitHub Desktop.
bash script template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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