0
有問題確保-v
和-o
都是必需元素,但-h
不在我的getopts中。我該如何解決這個問題?getopts秒旗不是必需的?
usage() { echo "Usage: $0 [-v <5.x|6.x>] [-o <string>]" 1>&2; exit 1; }
if (! getopts ":v:o:h" opt); then
echo "Usage: `basename $0` options (-v [version]) (-o [organization unit]) -h for help";
exit $E_OPTERROR;
fi
while getopts ":v:o:h" opt; do
case $opt in
v) vermajor=$OPTARG;;
o) org_unit=$OPTARG;;
h) usage;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1;;
:) echo "Option -$OPTARG requires an argument." >&2; exit 1;;
esac
done
exit