要取得剪贴板的内容

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

要取得剪贴板的内容

#1

帖子 eexpress » 2007-04-10 10:07

shell如何取得ctrl-c到剪贴板的文字,似乎是cutbuffer0-7中间的内容?
● 鸣学
头像
laborer
帖子: 1016
注册时间: 2005-10-25 11:15
联系:

#2

帖子 laborer » 2007-04-10 14:13

代码: 全选

$ apt-cache show xclip
Package: xclip
Priority: optional
Section: universe/x11
Installed-Size: 72
Maintainer: Baruch Even <baruch@debian.org>
Architecture: i386
Version: 0.08-6
Depends: libc6 (>= 2.4-1), libice6, libsm6, libx11-6, libxext6, libxmu6, libxt6
Filename: pool/universe/x/xclip/xclip_0.08-6_i386.deb
Size: 16028
MD5sum: 458b3496396a7c6989afaa7aa79955a0
SHA1: 68a16193d7684f61adff0490cb4294bd753cbbbc
SHA256: 22c3c3a12b8cc55826d13f67a818bed99992f9a4e8d9adf5d11c91b987ab97be
Description: command line interface to X selections
 xclip is a command line utility that is designed to run on any system with an
 X11 implementation. It provides an interface to X selections ("the clipboard")
 from the command line. It can read data from standard in or a file and place
 it in an X selection for pasting into other X applications. xclip can also
 print an X selection to standard out, which can then be redirected to a file
 or another program.
 .
 Homepage: http://people.debian.org/~kims/xclip/
Bugs: mailto:ubuntu-users@lists.ubuntu.com
Origin: Ubuntu
hreiser@oakland:~$ killall -9 wife
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#3

帖子 eexpress » 2007-04-10 15:35

这个是选择的文字啊。不是ctrl-c的啊。我浏览器里面复制一个链接,用右键菜单。是要这种
● 鸣学
头像
5luoya
帖子: 146
注册时间: 2006-10-31 14:41

#4

帖子 5luoya » 2007-04-10 16:29

粘贴?偶这里用 ctrl + shift + v。
头像
5luoya
帖子: 146
注册时间: 2006-10-31 14:41

#5

帖子 5luoya » 2007-04-10 16:31

sorry,答非所问。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#6

帖子 eexpress » 2007-04-10 21:31

i got it. wahaha

代码: 全选

xsel --clipboard
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#7

帖子 eexpress » 2007-04-10 21:32

Selecting text
There are some handy mouse shortcuts for selecting text. As normal a left mouse button drag, selects text but some apps also allow the right mouse button to extend the selection. I.E. you can click or drag the right button to define the extent of the selection. Also in general double clicking selects a word, while triple clicking selects a line (try it now).
Once text is selected X has 2 "clipboards" to put it in. The "selection buffer" and the "clipboard".
The selection buffer
This buffer is updated automatically when you select any text, and is generally the handiest buffer to use, as you can paste from it by clicking the middle mouse button at the required destination. I.E. by clicking the scroll button, or if you only have 2 mouse buttons you can click both simultaneously to emulate the middle mouse button.
The clipboard
This works much like the windows equivalent. In general apps use the same keys as in windows to control it. I.E. CtrlInsert or Ctrlc for copy, and ShiftInsert or Ctrlv for paste etc. These key combinations may conflict with the app so for example gnome-terminal uses ShiftCtrlc and ShiftCtrlv instead, so more generally one can select copy,cut,paste from the edit menu.
Buffer storage
Note it's the X application itself that maintains the storage for what it "puts" on the buffers, which makes a lot of sense when you think about it, especially considering X's network transparency. But that means when you close the application the content of the clipboard and selection buffer are lost.

You can get around this behaviour by using an external application to manage the storage for the clipboard, the standard one being xclipboard. Note this is the reason why it's awkward to get a command line program to paste to the clipboard. It has to fork and run until no longer required (someone else pastes to the clipboard). Search for xsel for an example of this.
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#8

帖子 eexpress » 2007-04-10 21:35

● 鸣学
lb_bn
帖子: 1261
注册时间: 2007-02-25 16:56

#9

帖子 lb_bn » 2007-04-11 10:28

这个比windows先进多了。。。
回复