Created
October 20, 2015 21:12
-
-
Save rlamana/576c4ace61b1ecd6f26a to your computer and use it in GitHub Desktop.
Command/Subcommand Bash Script Template
This file contains 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 | |
VERSION="0.1" | |
DESCRIPTION="Command/Subcommand line script template" | |
usage() { | |
echo "Usage: $0 [ subcommand [-c num] ] [-v]" 1>&2; exit 1; | |
} | |
subcommand() { | |
local OPTIND | |
OPTIND=2 | |
while getopts ":c:" opt; do | |
case "${opt}" in | |
c) | |
cl=${OPTARG} | |
echo "${cl}" | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
} | |
default() { | |
local OPTIND | |
while getopts ":v" opt; do | |
case "${opt}" in | |
v) | |
echo -e "${DESCRIPTION}, Version v${VERSION}" | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
usage | |
} | |
case "$1" in | |
validate) | |
subcommand "$@" | |
;; | |
*) | |
default "$@" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment