Skip to content

Instantly share code, notes, and snippets.

@hauke96
Last active May 12, 2018 16:34
Show Gist options
  • Save hauke96/2a33a10375458372d79cde076d5775c8 to your computer and use it in GitHub Desktop.
Save hauke96/2a33a10375458372d79cde076d5775c8 to your computer and use it in GitHub Desktop.
# Parses the install specific arguments
# Needed parameter: $@
function parse_install_args(){
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 for the install command 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#*=}
;;
*)
echo "Unknown argument number $i: '$arg'"
parsing_succeeded=false
;;
esac
done
}
arg=${@:1:1}
# To parse the next argument and not the command again
shift
# First we accept a command or the help-flag
case $arg in
-h|--help)
echo "Show help text here"
exit 0
;;
install)
command=install
parse_install_args $@
;;
*)
echo "Unknown command '$command'."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment