Skip to content

Instantly share code, notes, and snippets.

@jfollmann
Forked from IlyaKisil/snippets.sh
Created December 17, 2019 12:31
Show Gist options
  • Save jfollmann/495dca347effbb893c4918cecdb6ffca to your computer and use it in GitHub Desktop.
Save jfollmann/495dca347effbb893c4918cecdb6ffca to your computer and use it in GitHub Desktop.
[Snippets] Snippets for bash
#!/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 <test_user@gmail.com>
Report bugs to <TEST_USER@gmail.com>.
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