bash传参的使用记录

cat > 1.sh << \EOF
temp=$(getopt -o V:U:P:h --long version:,username:,password:,help -- "$@")

#将规范化后的命令行参数分配至位置参数($1,$2,...)
eval set -- $temp

echo $temp

while true; do
  case "$1" in
  -h | --help)
    usage
    exit 0
    ;;
  -V | --version)
    PARAMETER_VERSION=$2
    shift 2
    ;;
  --)
    shift
    break
    ;;
  *)
    echo "Internal error!"
    usage
    exit 1
    ;;
  esac
done
echo PARAMETER_VERSION $PARAMETER_VERSION
EOF
bash 1.sh  --version 123
posted @ 2021-10-29 09:44  汉克书  阅读(34)  评论(0编辑  收藏  举报