Skip to content

Instantly share code, notes, and snippets.

@reikind
Created January 17, 2013 13:51
Show Gist options
  • Save reikind/4556021 to your computer and use it in GitHub Desktop.
Save reikind/4556021 to your computer and use it in GitHub Desktop.
exsample for show batch log message.
#!/bin/bash
usage() {
cat << EOT
usage $0 [OPTIONS]
OPTIONS
-h show this usage
-q not show log message (without error message)
EOT
}
# if it is not empty, does not show log
QUIET=
## log function ##
log() {
test -z "$QUIET" && echo "$*"
}
debug() {
log "DEBUG $*"
}
info() {
log "INFO $*"
}
warn() {
log "WARN $*"
}
err() {
# output to STDERR
echo "ERR $*" 1>&2
}
while getopts "hq" option; do
case $option in
q)
QUIET=1
;;
\?)
echo "wrong option."
usage
exit 1
;;
h)
usage
exit 0
;;
esac
done
shift $(($OPTIND - 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment