Created
May 18, 2021 14:11
-
-
Save parsley42/6563b098391da0a74a6d3d219b0386c5 to your computer and use it in GitHub Desktop.
Shell 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
#!/bin/bash -e | |
trap_handler() | |
{ | |
ERRLINE="$1" | |
ERRVAL="$2" | |
echo "line ${ERRLINE} exit status: ${ERRVAL}" | |
# The script should usually exit on error | |
exit $ERRVAL | |
} | |
trap 'trap_handler ${LINENO} $?' ERR | |
for REQUIRED in git jq | |
do | |
if ! which $REQUIRED >/dev/null 2>&1 | |
then | |
echo "Required '$REQUIRED' not found in \$PATH" | |
fi | |
done | |
while getopts ":t:" OPT; do | |
case $OPT in | |
t ) | |
target=$OPTARG | |
;; | |
\? ) | |
echo "Invalid option: $OPTARG" >&2 | |
;; | |
: ) | |
echo "Invalid option: $OPTARG requires an argument" >&2 | |
;; | |
esac | |
done | |
shift $((OPTIND -1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment