views:

1393

answers:

3

Is it possible to pipe to/from the clipboard in bash? Whether it's piping to/from a device handle or using an auxiliary application, I can't find anything.

For example, if /dev/clip was a device linking to the clipboard we could do:

cat /dev/clip        # dump the contents of the clipboard
cat foo > /dev/clip  # dump the contents of "foo" into the clipboard
+3  A: 

There are different clipboards in linux, the X server has one, the window manager might have another one, etc. There is no standard device.

Oh, yes, on CLI, the screen program has its own clipboard as well, as do some other applications like emacs and vi.

In X, you can use xclip.

You can check this thread for other possible answers: http://unix.derkeiler.com/Newsgroups/comp.unix.shell/2004-07/0919.html

Sunny
It sounds like creating /dev/clip would be a good project for someone.
T.E.D.
I am perfectly aware of the multiple clipboards. How does this make my question any more difficult to answer?
marcog
Check the edits, I needed time to get the resources.
Sunny
+3  A: 

Try xclip, (man).

Zoredache
Sweet, this is perfect! :)
marcog
+8  A: 

You're a little ambiguous. I expect you're probably a Linux user inside X who wants to put stuff in the X PRIMARY clipboard.

It's important to understand that bash doesn't have a clipboard. There is no such thing as "the" clipboard, because bash can run on Windows, Mac OS X, lots of other OSes, inside X, outside X, ... Not to mention that X itself has three different clipboards itself. There's a wealth of clipboards you could be dealing with. Usually the clipboard you want to talk to has a utility that lets you talk to it.

In case of X, yes, there's xclip (and others).

If you're trying to talk to the Mac OS X clipboard, there's pbcopy.

If you're in Linux terminal mode (no X) then maybe you need to look into gpm.

There's also GNU screen which has a clipboard. To put stuff in there, look at the screen command "readreg".

For Windows, I expect cygwin will have a tool.

lhunath