xclip 命令行上的缩写长选项

Tim*_*Tim 5 options xclip

在联机帮助页中xclip

-selection

specify which X selection to use, options are 
"primary" to use XA_PRIMARY (default), 
"secondary" for XA_SECONDARY or 
"clipboard" for XA_CLIPBOARD

Note that only the first character of the selection specified with the -selection option is important. 
This means that "p", "sec" and  "clip"  would
have the same effect as using "primary", "secondary" or "clipboard" respectively.
Run Code Online (Sandbox Code Playgroud)

以下为使用剪贴板选择的工作原理

    xclip -sel clip < ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)

联机帮助页说clipboard可以缩短为clip,但没有说-selection可以缩短为-sel

那么为什么它有效呢?用于指定选项的此功能是否属于xclip或除此之外还属于许多其他应用程序xclip

Tho*_*key 3

xclip使用 X Toolkit 库来进行选项解析。所有选项都可以缩写。如果存在歧义,该库只会给出错误。

当然,选项是-select可以缩写为-sel(甚至可能-s)之类的东西。

xterm使用相同的库,相同的行为。它使用特殊情况(库外)使命令成为-v等的唯一缩写-version

X Toolkit 使用单个破折号-作为选项,并且不区分“短”和“长”,因为它不是getopt. 正如我在单字符选项的单破折号---中指出的,但单词的双破折号?,它与 GNU getopt 大约在同一时间引入,后者确实扩展了getopt. 这是在 POSIX 出现之前,但已经使用了几年,确立了它在单字符选项中的作用。GNU使用双破折号来表示选项。AT&T getoptgetopt--

xclip注意一个很长的题外话,您可以从其git 存储库中阅读 GNU getopt 的源代码(与 无关) ,例如,

 369    Long-named options begin with `--' instead of `-'.
 370    Their names may be abbreviated as long as the abbreviation is unique
 371    or is an exact match for some defined option.  If they have an
 372    argument, it follows the option name in the same ARGV-element, separated
 373    from the option name by a `=', or else the in next ARGV-element.
 374    When `getopt' finds a long-named option, it returns 0 if that option's
 375    `flag' field is nonzero, the value of the option's `val' field
 376    if the `flag' field is zero.
Run Code Online (Sandbox Code Playgroud)