gpt4 book ai didi

java - 什么样的应用程序使用 getopt "return in order"行为?

转载 作者:可可西里 更新时间:2023-11-01 11:49:50 24 4
gpt4 key购买 nike

引自getopt() Linux Manual page :

If the first character of optstring is a hyphen (-), then each nonoption argv-element is handled as if it were the argument of an option with character code 1. (This is used by programs that were written to expect options and other argv-elements in any order and that care about the ordering of the two.) The special argument double hyphens (--) forces an end of option-scanning regardless of the scanning mode.

引自manual page of Java GetOpt class :

...The second is to allow options anywhere, but to return all elements in the order they occur on the command line. When a non-option element is ecountered, an integer 1 is returned and the value of the non-option element is stored in optarg is if it were the argument to that option. For example, "-a foo -d", returns first 'a', then 1 (with optarg set to "foo") then 'd' then -1. When this "return in order" functionality is enabled, the only way to stop getopt() from scanning all command line elements is to use the special "--" string by itself as described above. An example is "-a foo -b -- bar", which would return 'a', then integer 1 with optarg set to "foo", then 'b', then -1. optind would then point to "bar" as the first non-option argv element. The "--" is discarded.

是的,我明白上面的说法在说什么,但我仍然无法想象什么样的应用程序会使用这种行为。

有人可以提供一个命令行语法的示例,该示例可能被实现“按顺序返回”行为的应用程序使用吗?

最佳答案

find 是混合选项和非选项参数并关心顺序的命令示例。

关于java - 什么样的应用程序使用 getopt "return in order"行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14411449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com