-
-
Save jfollmann/495dca347effbb893c4918cecdb6ffca to your computer and use it in GitHub Desktop.
[Snippets] Snippets for bash
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
#!/usr/bin/env bash | |
set -e | |
function help() { | |
local _FILE_NAME | |
_FILE_NAME=`basename ${BASH_SOURCE[0]}` | |
cat << HELP_USAGE | |
Description: | |
Usage: $_FILE_NAME [-h|--help] [-o=|--option=<option_value>] | |
Examples: | |
$_FILE_NAME -o=my_value | |
$_FILE_NAME --option=my_value | |
Options: | |
-h|--help | |
Show this message. | |
-o=|--option=<option_value> | |
Use key value option. | |
Author: | |
YOUR NAME AND CONTACT INFO | |
e.g. Test User <[email protected]> | |
Report bugs to <[email protected]>. | |
HELP_USAGE | |
} | |
# Utility functions | |
# Default values for variables | |
option_value="default_value" | |
# Parse arguments | |
for arg in "$@"; do | |
case $arg in | |
-h|--help) | |
help | |
exit | |
;; | |
-o=*|--option=*) | |
option_value="${arg#*=}" | |
;; | |
*) | |
# Skip unknown option | |
;; | |
esac | |
shift | |
done | |
# Define new variables with respect to the parsed arguments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment