4
为什么此选项仅在第一次使用时才起作用,然后在其他时间忽略?这就像它在不使用该选项时被重置。为什么getopts只能在第一次使用?
这里是我的功能:
testopts() {
local var="o false"
while getopts "o" option; do
case "${option}" in
o)
var="o true"
;;
esac
done
echo $var
}
当运行它,它传递的第一次选择时只返回true。
$ testopts o false $ testopts -o o true $ testopts -o o false
谢谢!将在2分钟内接受 –