Skip to content

Instantly share code, notes, and snippets.

@stefano-garzarella
Last active July 18, 2018 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefano-garzarella/b57038ac54e1e70ccc809a38e216b3b1 to your computer and use it in GitHub Desktop.
Save stefano-garzarella/b57038ac54e1e70ccc809a38e216b3b1 to your computer and use it in GitHub Desktop.
parse shell parameters
RED='\033[0;31m'
NC='\033[0m' # No Color
function usage
{
echo -e "usage: $0 [OPTION...]"
echo -e ""
echo -e "Simple description"
echo -e ""
echo -e " -s, --set X.Y set parameter"
echo -e " -f, --flag set flag"
echo -e " -h, --help print this help"
}
SET="default"
FLAG=0
while [ "$1" != "" ]; do
case $1 in
-s | --set )
shift
SET=$1
;;
-f | --flag )
FLAG=1
;;
-h | --help )
usage
exit
;;
* )
echo -e "\n${RED}Parameter not found:${NC} $1\n"
usage
exit 1
esac
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment