Skip to content

Instantly share code, notes, and snippets.

@parsley42
Created May 18, 2021 14:11
Show Gist options
  • Save parsley42/6563b098391da0a74a6d3d219b0386c5 to your computer and use it in GitHub Desktop.
Save parsley42/6563b098391da0a74a6d3d219b0386c5 to your computer and use it in GitHub Desktop.
Shell script template
#!/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