Created
September 5, 2017 14:02
-
-
Save Buravo46/67fd04207ee4d117a850dff696429a75 to your computer and use it in GitHub Desktop.
【Bash】コマンドやオプションなどを使用したい場合のテンプレートシェルスクリプト
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 | |
# Command | |
COMMAND=$(basename ${0}) | |
# SubCommand | |
SUB_COMMAND=${1} | |
shift | |
# Default | |
OPTION="DEFAULT" | |
function usage { | |
cat <<EOF | |
Usage: | |
${COMMAND} [command] [<options>] | |
Command: | |
command command | |
help help | |
Options: | |
--option -o option | |
EOF | |
} | |
function command { | |
echo "command "${OPTION} | |
} | |
# OPTION | |
while [ $# -gt 0 ]; | |
do | |
case ${1} in | |
--option|-o) | |
OPTION=${2} | |
shift | |
;; | |
esac | |
shift | |
done | |
# COMMAND | |
case ${SUB_COMMAND} in | |
help) | |
usage | |
shift | |
;; | |
command) | |
command | |
shift | |
;; | |
*) | |
echo "[ERROR] ${COMMAND} ${SUB_COMMAND}" | |
usage | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment