Shell getopt Get Parameters

Source: Internet
Author: User

#!/bin/sh# description show_usage= "args: [-I,-P,-u,-w,-A,-s,-D,-v] [--ip=,--port=,--user=,--pwd=,--path=,--scrip t=,--debug=,--version=] "#参数opt_ip =" "opt_port=" "opt_user=" "opt_pwd=" "opt_path=" "opt_script=" "opt_debug=" "Opt_ version= "" Getopt_args= ' getopt-o i:p:u:w:a:s:d:v:-al ip:,port:,user:,pwd:,path:,script:,debug:,version:--"[Email  protected] "' eval set--" $GETOPT _args "#获取参数while [-N" $ "]docase" $ in-i|--ip) opt_ip=$2; Shift 2;; -p|--port) opt_port=$2; Shift 2;; -u|--user) opt_user=$2; Shift 2;; -W|--PWD) opt_pwd=$2; Shift 2;; -a|--path) opt_path=$2; Shift 2;; -s|--script) opt_script=$2; Shift 2;; -d|--debug) opt_debug=$2; Shift 2;; -v|--version) opt_version=$2; Shift 2;; --) break;; *) echo $1,$2, $show _usage; break;;  Esacdoneif [[-Z $opt _ip | |-Z $opt _port | |-Z $opt _user | |-Z $opt _pwd | |-Z $opt _path | |-Z $opt _script | | z $opt _DEBUG || -Z $opt _version]]; Thenecho $show _usageecho "opt_ip:" $opt _ip ", Opt_port:" $opt _port ", Opt_user:" $opt _user ", opt_pwd:" $opt _pwd ", Opt_paTh: "$opt _path", Opt_script: "$opt _script", Opt_debug: "$opt _debug", opt_version: "$opt _versionexit 0fi# start processing #ip port User PWD Connection Server #script path debug version as parameter execution



There are several keys that will be ignored where the failure occurs:

Eval set--"$GETOPT _args" eval keyword is required, there are many examples on the Web no, Pit daddy

Getopt_args= ' getopt-o i:p:u:w:a:s:d:v:-al ip:,port:,user:,pwd:,path:,script:,debug:,version:--"[email protected]" `

The last--also necessary, many examples on the internet are not, Pit daddy



Shell getopt Get Parameters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.