opt 字符后面的 - 有何作用?

问题描述 投票:0回答:1

我看到了这样的 getopts 用法:

while getopts ":hv-:" optchar; do
...
done

最后一个 - 有什么用,它和 v 选项有什么关系?

shell getopts
1个回答
0
投票

在 shell 脚本中的 getopts 上下文中,最后一个 - 用于表示选项的结束。这通常称为“双破折号”或“选项结束”标记。它告诉 getopts 出现在该标记之后的任何参数都应被视为位置参数而不是选项。

© www.soinside.com 2019 - 2024. All rights reserved.