#!/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