Is there an Environment Variable that contains the

2020-04-15 12:48发布

Is there a Bash environment variable (say $CLIPBOARD or similar) that contains the current contents of the clipboard?

The specific example is to see the top 20 lines of a file whose path I have just copied into the clipboard.

  1. Copy path with Ctrl-C
  2. Switch to terminal
  3. Type more, Ctrl-V

UPDATE: I'm running on CentOS 4

5条回答
Juvenile、少年°
2楼-- · 2020-04-15 12:56

You might look into xclip or pbcopy/pbpaste (Mac OS X).

查看更多
Rolldiameter
3楼-- · 2020-04-15 13:05

Using xclip combined with Readline bindings in Bash - a bit of a hack, but it works

http://bash-hackers.org/wiki/doku.php/snipplets/xclip

查看更多
干净又极端
4楼-- · 2020-04-15 13:08

No, there isn't a bash environment variable. For your platform (which you don't specify) you may be able to use a command line tool like xclip or one of the many Windows utilities (google for "windows clipboard command line").

查看更多
来,给爷笑一个
5楼-- · 2020-04-15 13:09

I don't really know exactly what you are trying to accomplish. Check out the following article and see if it helps: Remotely transferring clipboard data using netcat and bash

Update: If you are using OSX, try using pbcopy & pbpaste to copy and paste data from the clipboard.

查看更多
我想做一个坏孩纸
6楼-- · 2020-04-15 13:13

This requires an additional command-line utility, but it looks like what you describe:

Command Line to Clipboard

查看更多
登录 后发表回答