Skip to content

Instantly share code, notes, and snippets.

@orca8
Last active June 5, 2016 10:59
Show Gist options
  • Save orca8/c262f819a51eee0b71871c8d950f13d1 to your computer and use it in GitHub Desktop.
Save orca8/c262f819a51eee0b71871c8d950f13d1 to your computer and use it in GitHub Desktop.
shellscript template
#!/bin/bash
set -eu
function usage {
cat <<EOF
$(basename ${0}) is a tool for ...
Usage:
$(basename ${0}) [<options>]
Options:
--debug, -d run debug mode
--version, -v print $(basename ${0}) version
--help, -h print this
EOF
}
function version {
echo "$(basename ${0}) version 1.0.0"
}
readonly RED=31
readonly GREEN=32
readonly YELLOW=33
readonly BLUE=34
# cecho $RED "hello"
function cecho {
color=$1
shift
echo -e "\033[${color}m$@\033[m"
}
# set option
DEBUG=false
while [ $# -gt 0 ];
do
case ${1} in
--debug|-d)
set -x
DEBUG=true
readonly DEBUG
;;
--version|-v)
version
exit 0
;;
--help|-h)
usage
exit 0
;;
*)
cecho $RED "[ERROR] Invalid option '${1}'"
usage
exit 1
;;
esac
shift
done
# below program
# alias ls='ls --color=always'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment