亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于getopt語法錯誤

關于getopt語法錯誤

明月笑刀無情 2021-04-11 20:17:30
好吧,我是一個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 回答

  • 1 回答
  • 0 關注
  • 525 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號