Skip to content

Instantly share code, notes, and snippets.

@mu-777
Created January 21, 2022 10:16
Show Gist options
  • Save mu-777/a20a270d5209cb8cc43a41b8fc0ae991 to your computer and use it in GitHub Desktop.
Save mu-777/a20a270d5209cb8cc43a41b8fc0ae991 to your computer and use it in GitHub Desktop.
#!/bin/bash
function usage () {
cat << EOS
Usage:
$(basename ${0}) [OPTIONS]... MUST_ARG
Options:
--help, -h print this
--option, -o optional arg
EOS
}
OPT=`getopt -o ho: -l help,option: -- "$@"`
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- "$OPT"
MUST_ARG=""
OPT_ARG=""
while true
do
case $1 in
-o | --option)
OPT_ARG=$2
shift 2
;;
--)
MUST_ARG=$2
shift
break
;;
*)
usage
exit 1
;;
esac
done
if [ -z $MUST_ARG ]; then
echo "Must have MUST_ARG"
usage
exit 1
fi
if [ -z $OPT_ARG ]; then
OUT_ARG=default_val
echo "OUT_ARG is default($OUTDIR)"
fi
echo $MUST_ARG
echo $OUT_ARG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment