xclipコマンドラインの短縮された長いオプション

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.

クリップボードを使用して選択する方法は次のとおりです。

    xclip -sel clip < ~/.ssh/id_rsa.pub

マンページにはclipboardに短縮できると記載されていますが、 に短縮できるとclipは示していません。-selection-sel

それではなぜ動作しますか?オプションを指定するこの機能はxclip他の多くのアプリケーションに属していますか、それとも追加されますかxclip

ベストアンサー1

xclipオプションの解析には X Toolkit ライブラリを使用します。すべてのオプションは省略できます。あいまいさがある場合、ライブラリはエラーを表示します。

もちろん、オプションは-selectと省略することができます-sel(可能です)。-s

xterm同じライブラリ、同じ動作を使用します。特殊な場合(ライブラリの外部)を使用して、-vコマンドを一意の略語にします-version

Xツールキットは-オプションに単一のダッシュを使用し、私が指摘したように、「短い」と「長い」を区別しませんgetopt-単一文字オプションには単一のダッシュがあり、--単語には二重ダッシュがありますか?、これはGNU getoptとほぼ同じ時期に導入されました。した延長するgetopt。 POSIX以前だったけどAT&T getopt長年の使用の終わりに、単一文字オプションでの役割が確立されました。 GNUはgetopt二重ダッシュを使用--して長いオプション。

xclipGNU getoptのソースコードを読むための長い余談を参照してください(関連なし)。Gitリポジトリ、例えば、

 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.

おすすめ記事