Skip to content

Instantly share code, notes, and snippets.

@warlord0

warlord0/template.sh

Last active Nov 9, 2020
Embed
What would you like to do?
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