Skip to content

Instantly share code, notes, and snippets.

@muresan
Created July 2, 2019 12:55
Show Gist options
  • Save muresan/b5a7399271187ae529a34c1d8eb45dc8 to your computer and use it in GitHub Desktop.
Save muresan/b5a7399271187ae529a34c1d8eb45dc8 to your computer and use it in GitHub Desktop.
#!/bin/bash
LONG_OPTIONS="long:,short:"
LONG_PARAMETERS="^(long|longer|longest)$"
LONG=default_long
SHORT_OPTIONS="l:s:"
SHORT_PARAMETERS="^(short|shorter|shortest)$"
SHORT=default_short
options=$(getopt --longoptions "$LONG_OPTIONS" --options "$SHORT_OPTIONS" -- "$@")
[ $? -eq 0 ] || {
echo "Invalid options provided: "
exit 1
}
#echo $options
eval set -- "$options"
while true; do
case "$1" in
-l|--long)
LONG=$2
[[ ! $LONG =~ $LONG_PARAMETERS ]] && {
echo "Incorrect parameter provided for $1: $2"
exit 1
}
shift;
;;
-s|--short)
SHORT=$2
[[ ! $SHORT =~ $SHORT_PARAMETERS ]] && {
echo "Incorrect parameter provided for $1: $2"
exit 1
}
shift;
;;
--)
shift
break
;;
esac
shift
done
echo $LONG , $SHORT
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment