while [ $# -gt 0 ]; do
case $1 in
-h|--help)
print_help
exit 0
;;
-V|--version)
print_version
exit 0
;;
-l|--listen)
listening_address=$2
shift 2
;;
-p|--port)
lipo=$2
shift 2
;;
-P|--protocol)
proto=$2
shift 2
;;
-v|--verbose)
verbose=true
shift
;;
--)
shift
break
;;
*)
echo "Internal Error: option processing error: $1" 1>&2
exit 1
;;
esac
done看一个shell源码时学习到的,用shift 命令归位当前长度,然后做while循环,很有技巧。