[英]For two consecutive options, `getopts` taking the second option as the argument of first
[英]The getopts command not taking in multiple options that require an argument
我在使用 getopts 命令時遇到問題。
當我想使用需要 SAME 參數的選項時,它會在第一個需要參數的選項(例如 -i )之后停止運行程序。 因此,當我希望它采用選項 -id 或 -i -d 時,它將在使用“-i”選項后停止運行 while 循環並忽略 -d 選項。
如何讓循環繼續並執行 -d 選項?
傳遞的 arguments 的格式可以是:“-id 參數”或“-i -d 參數”
我目前正在使用 $p 來獲取當前為每個選項傳遞的最后一個參數。 這是破折號中的 linux ubuntu shell:
To make the code smaller and quicker to read:
for p do :; done
echo arguments === $1 $2 $3
echo p = $p
while getopts ":hva:b:d:g:i:u:w:" opt;
do
case "$opt" in
i)
checkdir $p
fileinfo $p
;;
***OTHER OPTIONS FOLLOW SIMILAR FORMAT***
esac
done
當我想使用需要參數的選項時,它會在第一個需要參數的選項(例如 -i)之后停止運行程序。 因此,當我希望它采用選項 -id 或 -i -d 時,它會在使用“-i”選項后停止運行 while 循環。
如果您希望它采用選項... -i -d ,則必須(因為它們每個都需要一個參數)在每個選項之后立即提供一個參數,例如… -i argument1 -d argument2 …
。
使用-id
或-i -d
d
或-d
分別作為選項的參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.