在 bash 中打印系统剪贴板内容

Loo*_*oom 10 bash xorg clipboard

有一种方法可以将一些命令输出通过xclip.

some-command | xclip -selection clipboard
Run Code Online (Sandbox Code Playgroud)

我想执行反向任务 - 将系统剪贴板打印到终端。怎么做?

Bra*_*ley 8

根据联机帮助页,-o可以选择向xclip相反方向推送数据:

   -i, -in
          read text into X selection from standard input or files (default)

   -o, -out
          prints the selection to standard out (generally for piping to a file or program)
Run Code Online (Sandbox Code Playgroud)

在您的上述命令中,-i假设为 。


ter*_*don 7

另一种选择是xsel程序:

By default, this program outputs the selection without modification  if
   both  standard  input  and standard output are terminals (ttys). Other?
   wise, the current selection is output if standard output is not a  ter?
   minal  (tty),  and the selection is set from standard input if standard
   input is not a terminal (tty). If any input or output options are given
   then the program behaves only in the requested mode.
Run Code Online (Sandbox Code Playgroud)

因此,只需将某些内容复制到剪贴板并运行xsel以将其打印到终端。您可以通读man xsel更高级的选项,例如应该使用哪个剪贴板等。

  • 为了简化事情......这就是我所做的:`alias pbcopy='xsel --clipboard --input'; alias pbpaste='xsel --clipboard --output' ` 我选择了名称以匹配 MacOS 命令。 (5认同)