Created
April 23, 2013 21:17
-
-
Save akbortoli/5447480 to your computer and use it in GitHub Desktop.
Shell: Function and Flags
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
#!/bin/bash | |
function help () | |
{ | |
echo "A simple script." | |
echo "" | |
echo " ./test.sh abc - include jasmine in the project"; | |
} | |
function abc() | |
{ | |
local OPTIND | |
if [[ -z "$1" ]]; then | |
echo "abc requires arguments"; | |
exit 1 | |
fi | |
while getopts ":a: :b" opt; do | |
case $opt in | |
a) | |
echo "-a was triggered, Parameter: $OPTARG" >&2 | |
;; | |
b) | |
echo "-b was triggered" >&2 | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
} | |
if [ $1 ]; then | |
case "$1" in | |
abc) | |
shift; | |
abc "$@" | |
;; | |
*) | |
help; | |
;; | |
esac | |
else | |
help; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment