#!/bin/bash
# Desc:
# Author:
# Date:2020-02-22
####################################
# getopt -T
# ARGS=`getopt -o ab:c:: --long along,blong:,clong:: -n "getopt.sh" -- "$@"`
# if [ $? != 0 ];then
# echo "Terminating" >&2;exit 1
# fi
ARGS=`getopt -o ab:c:: --long along,blong:,clong:: -n 'test.sh' -- "$@"`
if [ $? != 0 ];then
echo "Terminating..."
exit 1
fi
eval set -- "${ARGS}"
while true
do
case "$1" in
-a|--along)
echo "option a"
shift ;;
-b|--blong)
echo "option b argument $2"
shift 2;;
-c|--clong)
case "$2" in
"")
echo "Option c, no argument"
shift 2;;
*)
echo "option c, argumnt $2"
shift 2;;
esac
;;
--)
shift
break
;;
*)
echo "Internal error!"
exit 1
;;
esac
done
原文链接:https://blog.51cto.com/2242558/1545331