Skip to content

Instantly share code, notes, and snippets.

@abhishekbh
Created January 24, 2018 00:02
Show Gist options
  • Save abhishekbh/b4583faedafaf9956f900ea2480178d6 to your computer and use it in GitHub Desktop.
Save abhishekbh/b4583faedafaf9956f900ea2480178d6 to your computer and use it in GitHub Desktop.
getopt for long flag reads
#!/bin/bash
if ! options=$(getopt -o abc: -l along,blong,clong: -- "$@")
then
exit 1
fi
while [ $# -gt 0 ]
do
case $1 in
-a|--along) echo "a or along" ;;
-b|--blong) echo "b or blong" ;;
(--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment