Last active
May 12, 2018 16:35
-
-
Save hauke96/2e8c8630906bc5253c84ed83751e045b to your computer and use it in GitHub Desktop.
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 | |
# Global variables | |
package= | |
command= | |
# Some have default values | |
parsing_succeeded=true | |
for (( i=1; i<=$#; i++ )) | |
do | |
arg=${@:$i:1} # Gets the string i | |
val=${@:$i+1:1} # Gets the string i+1 | |
case $arg in | |
-h|--help) | |
echo "Show help text here" | |
exit 0 | |
;; | |
-p) | |
package=$val | |
# The parse the next argument and not this value | |
((i++)) | |
;; | |
--package=*) | |
# Split at = char and remove the shortest match from beginning | |
package=${arg#*=} | |
;; | |
-i|--install) | |
command="install" | |
;; | |
-r|--remove) | |
command="remove" | |
;; | |
*) | |
echo "Unknown argument number $i: '$arg'" | |
parsing_succeeded=false | |
;; | |
esac | |
done | |
echo "Arguments:" | |
echo " package: $package" | |
echo " command: $command" | |
echo "" | |
if [ "$parsing_succeeded" == "true" ] | |
then | |
if [ ! -z $command ] | |
then | |
echo "Start command: '$command'" | |
# Check and start the corresponding routine here | |
else | |
echo "Missing command" | |
exit 1 | |
fi | |
else | |
echo "Error during parsing. Exit application." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment