Skip to content

Instantly share code, notes, and snippets.

@moukrea
Created June 9, 2022 14:20
Show Gist options
  • Select an option

  • Save moukrea/d7e0492f7d46ff81e286a5f0d222267c to your computer and use it in GitHub Desktop.

Select an option

Save moukrea/d7e0492f7d46ff81e286a5f0d222267c to your computer and use it in GitHub Desktop.
Shell - Get command line arguments
#!/bin/bash
args=$(getopt -o a:,b --long alpha:,beta -n "" -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "${args}"
while true; do
case "${1}" in
-a | --alpha ) ALPHA="${2}"; shift 2 ;;
-b | --beta ) BETA=gamma; shift 1 ;;
* ) echo "${1}"; break ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment