Skip to content

Instantly share code, notes, and snippets.

@nhoag
Last active January 16, 2016 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhoag/e97200b008761cdab183 to your computer and use it in GitHub Desktop.
Save nhoag/e97200b008761cdab183 to your computer and use it in GitHub Desktop.
Bash Script Boilerplate
#!/bin/bash
set -a ; set -o errexit ; set -o nounset
function usage() {
cat <<EOF
Usage: ${0} ARG
OPTIONS:
-h Show usage
EOF
exit
}
while getopts ":h" OPTION; do
case $OPTION in
h) usage ;;
esac
done
shift $((OPTIND - 1))
if [ $# -eq 0 ]; then
usage
fi
if [[ ! -f $HOME/.example ]]; then
printf 'Enter username for Example: '
read -r EXAMPLE_USER
printf 'Enter password for Example: '
read -rs EXAMPLE_PASS
echo
echo "${EXAMPLE_USER}:${EXAMPLE_PASS}" \
> "$HOME/.example"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment