-
-
Save paulogaspar7/8277158 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Created by Hugo Ferreira <[email protected]> on isoD. | |
# Copyright (c) 2012 Mindclick. All Rights Reserved. | |
# Licensed under the BSD License: http://creativecommons.org/licenses/BSD | |
readonly BASEDIR=$(cd "$(dirname "$0")" && pwd) # where the script is located | |
readonly CALLDIR=$(pwd) # where it was called from | |
# Script configuration | |
readonly CONSTANT="value" | |
# Script functions | |
function usage () { | |
echo " | |
Usage: $(basename $0) [options] param | |
-a, -b explanation of option a (alias b) | |
-n value explanation of option n with value | |
-h this usage help text | |
param description of the parameter | |
Description of the script. | |
Example: | |
$(basename $0) -a -n 1 something" | |
exit ${1:-0} | |
} | |
function askifempty () { | |
ask_val="$1"; ask_default="$2"; ask_msg="$3"; ask_options="$4" # pass "-s" for passwords | |
if [[ -z "$ask_val" ]]; then | |
read $ask_options -p "$ask_msg [$ask_default] " ask_val | |
fi | |
ask_val=$(echo ${ask_val:-$ask_default}) | |
echo "$ask_val" | |
} | |
# Exit and show help if the command line is empty | |
[[ ! "$*" ]] && usage 1 | |
# Initialise options | |
n_value="value if option is missing" | |
# Parse command line options | |
while getopts abn:h option; do | |
case $option in | |
a|b) is_flag=1 ;; | |
n) n_value=$OPTARG ;; | |
h) usage ;; | |
\?) usage 1 ;; | |
esac | |
done | |
shift $(($OPTIND - 1)); # take out the option flags | |
# Validate input parameters | |
parameter=$(askifempty "$1" "default value" "Enter the parameter value:") | |
echo $parameter | |
# Do the work | |
: | |
read -p "Press any key to continue..." -n1 -s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment