命令行参数,标准aproach解析? [英] Command line parameters, standard aproach to parse?
问题描述
我一直在读一些关于程序如何处理命令行参数。但是信息似乎是不完整,我读过的东西:
I've been reading a bit about how programs handle command line parameters. But the information seems to be "incomplete", things I've read:
- 选项可能有一个前面的' - '或'如果他们的前面。
- 选项可以有其他参数(不带 - 符号)
- 选项参数直接跟随选项,有或没有空格。 / li>
- 选项可以是单个字母或全字。
- 选项可以合并到单个选项中:-abc equals -a -b - c
- Options may have a preceding '-' or '/' sign if front of them.
- Options can have additional arguments (which go without a - sign)
- the option arguments follow the option directly, with or without a space.
- Options can be a single letter or a full word.
- optionscan be merged inside a single "option": -abc equals -a -b -c
现在我真的想知道:什么样的选项你给一个 -
也将选项合并为1似乎与全字选项不兼容? -file可以是一个完整的字,但它也可能意味着-f,-i,-l,-e,4个不同的开关。
Now I'm really wondering: What kind of options do you give a "-" sign and which not. Also the merging of options into 1 seems to be incompatible with full-word options? "-file" can be a full word, but it might also mean "-f", "-i", "-l", "-e", 4 different switches. Or even: "-f" with "ile" as option_argument.
我理解错了吗?
推荐答案
在像Linux这样的系统上,有一个约定:全字的选项使用两个破折号(例如 - file
-letter选项使用单个破折号(例如 -f
。)
On systems like Linux, there is the convention that options that are full words use two dashes (e.g. --file
), while single-letter options use a single dash (e.g. -f
.)
使用斜杠引入选项是来自旧DOS ,并保存在Windows中。
Using slash to introduce options is from old DOS, and is being kept in Windows.
此外,如果某个选项使用整个单词,则无法分割为多个选项。这是关于你的例子 -file
: -file
可以是一个选项,不同的选项( -f
, -i
, -l </ code>和
-e
)。
Also, if an option is using a whole word, it can not be split into several options. This is in regards to your example with -file
: -file
can either be one option, or four different options (-f
, -i
, -l
and -e
).
我建议你找一些你喜欢的方式,然后使用。
I would suggest you find some way you like, and then use that.
这篇关于命令行参数,标准aproach解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!