| # This script does the very simple job of echoing some text. If a '-d' (or |
| # '--debug') flag is given, additinal "debug" output is enabled. |
| # This script demonstrates the use of a boolean flag to enable custom |
| # functionality in a script. |
| # $ ./debug_output.sh speak |
| # $ ./debug_output.sh sing |
| # $ ./debug_output.sh --debug sing |
| DEFINE_boolean 'debug' false 'enable debug mode' 'd' |
| [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ] || return |
| die() { [ $# -gt 0 ] && echo "error: $@" >&2 |
| # Parse the command-line. |
| eval set -- "${FLAGS_ARGV}" |
| debug "I'm getting ready to say something..." |
| echo 'The answer to the question "What is the meaning of life?" is "42".' |
| debug "I'm getting ready to sing something..." |
| echo 'I love to sing! La diddy da dum!' |
| *) die "unrecognized command (${command})" ;; |