Created
August 19, 2013 08:12
-
-
Save espinielli/6266752 to your computer and use it in GitHub Desktop.
Snippet: bash with docco
This file contains hidden or 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/sh | |
# **scForUser** provides a list of SC IDs for user ACRONYM created within time interval provided. | |
# Usage and Prerequisites | |
# ----------------------- | |
# This tells bash that it should exit the script if any statement | |
# returns a non-true return value. | |
set -e | |
# This is a debug facility for shell scripts: if you set `_DEBUG="on"` | |
# you'll see debug info...look for `DEBUG` function use below. | |
_DEBUG=${_DEBUG:-"off"} | |
function DEBUG() | |
{ | |
if [ "x$_DEBUG" == "xon" ] | |
then | |
$@ | |
else | |
: | |
fi | |
} | |
# This is one way of handling usage message -- in two steps --: | |
# | |
# * you write the usage message in a comment -- typically right after | |
# the shebang line -- *BUT*, use a special comment prefix like `#/` | |
# so that it's easy to pull these lines out. | |
# Only comment lines padded with a space are considered documentation. | |
# A `#` followed by any other character is considered code. | |
# | |
#/usage: mycommand [ options ] arguments | |
#/ | |
#/Descriotion | |
#/ | |
#/Options: | |
#/ -s c use c for s | |
#/ --help print an help/usage message | |
#/ | |
#/Example: | |
#/ $ mycmd -s cucu | |
#/ few words | |
# | |
# * the second part of the usage message technique: `grep` yourself | |
# for the usage message comment prefix and then cut off the first few | |
# characters so that everything lines up. | |
expr -- "$*" : ".*--help" >/dev/null && { | |
grep '^#/' <"$0" | cut -c3- | |
exit 0 | |
} | |
DEBUG cat <<EOF | |
>> some text = $var | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment