Skip to content

Instantly share code, notes, and snippets.

@warlord0
Last active October 21, 2021 09:01
Show Gist options
  • Save warlord0/07fe11e75c4eb08902637734a5cef093 to your computer and use it in GitHub Desktop.
Save warlord0/07fe11e75c4eb08902637734a5cef093 to your computer and use it in GitHub Desktop.
Bash Script Template
#!/bin/bash
EXAMPLE="example default"
# Plugin variable description
PROGNAME=$(basename $0)
RELEASE="Revision 1.0.0"
AUTHOR="(c) 2020 Warlord0"
# Functions plugin usage
print_release() {
echo "$RELEASE $AUTHOR"
}
print_usage() {
echo ""
echo "$PROGNAME $RELEASE - Bash Script Template"
echo ""
echo "Usage: $PROGNAME"
echo ""
echo " -h Show this page"
echo ""
echo " -e | --example Example argument"
echo ""
echo "Usage: $PROGNAME --help"
echo ""
exit 0
}
print_help() {
print_usage
echo ""
echo "Bash script template"
echo ""
exit 0
}
# Parse parameters
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
print_help
exit 0
;;
-v | --version)
print_release
exit 0
;;
-e | --example)
shift
EXAMPLE=$1
;;
*)
echo "Unknown argument: $1"
print_usage
;;
esac
shift
done
if [[ -z "${EXAMPLE}" || -z "${EXAMPLE}" ]]; then
echo "Missing argument"
exit 1
fi
# Script body goes after here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment