术语之间的区别:“选项"、“参数"和“参数"? [英] Difference between terms: "option", "argument", and "parameter"?

查看:28
本文介绍了术语之间的区别:“选项"、“参数"和“参数"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些术语之间有什么区别:选项"、参数"和参数"?在手册页中,这些术语似乎经常互换使用.

What are the differences between these terms: "option", "argument", and "parameter"? In man pages these terms often seem to be used interchangeably.

推荐答案

command 被拆分为名为 arguments 的字符串数组.参数 0(通常)是命令名称、参数 1、命令后面的第一个元素,依此类推.这些参数有时称为位置参数.

A command is split into an array of strings named arguments. Argument 0 is (normally) the command name, argument 1, the first element following the command, and so on. These arguments are sometimes called positional parameters.

$ ls -la /tmp /var/tmp
arg0 = ls
arg1 = -la
arg2 = /tmp
arg3 = /var/tmp

选项 是一种记录类型的参数,用于修改命令的行为,例如-l 通常表示长",-v 冗长.-lv两个 选项组合在一个 单个 参数中.还有长选项,如--verbose(另见使用getopts处理长短命令行选项).顾名思义,选项通常是可选的.然而,有些命令具有自相矛盾的强制选项".

An option is a documented type of argument modifying the behavior of a command, e.g. -l commonly means "long", -v verbose. -lv are two options combined in a single argument. There are also long options like --verbose (see also Using getopts to process long and short command line options). As their name suggests, options are usually optional. There are however some commands with paradoxical "mandatory options".

$ ls -la /tmp /var/tmp
option1= -l
option2= -a

参数 是提供信息的参数命令或其选项之一,例如在-o file中,file-o选项的参数.与选项的可能值在程序中硬编码不同,参数通常不是,因此用户可以自由使用适合他/她需要的任何字符串.如果您需要传递一个看起来像选项但不应被解释为选项的参数,您可以使用双破折号将其与命令行的开头分开:--.

A parameter is an argument that provides information to either the command or one of its options, e.g. in -o file, file is the parameter of the -o option. Unlike options, whose possible values are hard coded in programs, parameters are usually not, so the user is free to use whatever string suits his/her needs. Should you need to pass a parameter that looks like an option but shouldn't be interpreted as such, you can separate it from the beginning of the command line with a double dash: --.

$ ls -la /tmp /var/tmp
parameter1= /tmp
parameter2= /var/tmp

$ ls -l -- -a
option1    = -l
parameter1 = -a

shell参数 是在 shell 上下文中存储值的任何东西.这包括位置参数(例如 $1$2...)、变量(例如 $foo$bar...) 和特殊字符(例如 $@)

A shell parameter is anything that store a value in the context of the shell. This includes positional parameters (e.g. $1, $2...), variables (e.g. $foo, $bar...) and special character ones (e.g. $@)

最后还有子命令,也称为函数/(低级)命令,与元命令"一起使用;嵌入了多个单独的命令,例如 busyboxgitapt-getopenssl 等.使用它们,您可能在子命令之前有全局选项,以及在子命令之后的子命令特定选项.与参数不同,可能的子命令列表在命令本身中进行了硬编码.例如:

Finally, there are subcommands, also known as functions / (low-level) commands, which are used with "metacommands" that embed multiple separate commands, like busybox, git, apt-get, openssl, and the likes. With them, you might have global options preceeding the subcommand, and subcommand specific options that follow the subcommand. Unlike parameters, the list of possible subcommands is hardcoded in the command itself. e.g.:

$ busybox ls -l
command            = busybox
subcommand         = ls
subcommand option1 = -l

$ git --git-dir=a.git --work-tree=b -C c status -s
command            = git
command option1    = --git-dir=a.git
command option2    = --work-tree=b
command option3    = -C c
subcommand         = status
subcommand option1 = -s

请注意,一些命令如 testtarddfind 的参数解析语法比前面描述的那些可以将其部分或全部参数解析为 expressionsoperandskeys 和类似的命令特定组件.

Note that some commands like test, tar, dd and find have more complex argument parsing syntax than the ones described previously and can have some or all of their arguments parsed as expressions, operands, keys and similar command specific components.

另请注意,可选变量赋值和重定向,尽管由 shell 处理以进行波浪号扩展、参数扩展、命令替换、算术扩展和引号删除等其他命令行参数,但在我的回复中并未考虑在内,因为它们已经当实际调用命令并传递其参数时消失.

Note also that optional variable assignments and redirections, despite being processed by the shell for tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal like other command line parameters are not taken into account in my reply because they have disappeared when the command is actually called and passed its arguments.

这篇关于术语之间的区别:“选项"、“参数"和“参数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆