Last active
July 18, 2018 09:38
-
-
Save stefano-garzarella/b57038ac54e1e70ccc809a38e216b3b1 to your computer and use it in GitHub Desktop.
parse shell parameters
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
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