Skip to content

Instantly share code, notes, and snippets.

@akbortoli
Created April 23, 2013 21:17
Show Gist options
  • Save akbortoli/5447480 to your computer and use it in GitHub Desktop.
Save akbortoli/5447480 to your computer and use it in GitHub Desktop.
Shell: Function and Flags
#!/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