好吧,我是一個getops和b一起玩的linux bash業余愛好者getop。我已經在幾個論壇上閱讀了有關該主題的幾次對話,但似乎無法使我的代碼正常工作。這是一個使用的小腳本getopts,可從該論壇回收:#!bin/bashwhile getopts ":a:p:" opt; do case $opt in a) arg_1="$OPTARG" ;; p) arg_2="$OPTARG" ;; \?) ;; esacdoneprintf "Argument firstArg is %s\n" "$arg_1"printf "Argument secondArg is %s\n" "$arg_2"它的工作是:bash test02.sh -asomestring -bsomestring2 #either with or without quotes#Argument firstArg is somestring#Argument secondArg is somestring2現在,由于我想嘗試使用長選項名稱,因此我正在嘗試getopt,試圖從網上發現的示例中理解語法:#!/bin/bashtemp=`getopt -o a:b: -l arga:,argb:--"$@"`eval set --"$temp"while true ; do case "$1" in a|arga) firstArg="$OPTARG" ;; b|argb) secondArg="$OPTARG" ;; \?) ;; esacdoneprintf "Argument firstArg is %s\n" "$firstArg"printf "Argument secondArg is %s\n" "$secondArg"上面的代碼不起作用:bash test04.sh -a'somestring' -b'somestring2' #either with or without quotes#getopt: invalid option -- 'b'#Try `getopt --help' for more information.#bash test04.sh --arga=somestring --argb=somestring2#getopt: unrecognized option '--argb=somestring2'#Try `getopt --help' for more information.你能幫我理解我的錯誤嗎?
- 1 回答
- 0 關注
- 525 瀏覽
添加回答
舉報
0/150
提交
取消