Created
January 17, 2013 13:51
-
-
Save reikind/4556021 to your computer and use it in GitHub Desktop.
exsample for show batch log message.
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 | |
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