Skip to content

Instantly share code, notes, and snippets.

@Buravo46
Created September 5, 2017 14:02
Show Gist options
  • Save Buravo46/67fd04207ee4d117a850dff696429a75 to your computer and use it in GitHub Desktop.
Save Buravo46/67fd04207ee4d117a850dff696429a75 to your computer and use it in GitHub Desktop.
【Bash】コマンドやオプションなどを使用したい場合のテンプレートシェルスクリプト
#! /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