11

I'm trying to give the following command:

echo "hi" | xclip -selection c

This doesn't work? It has worked in the past, but never consistently. I also tried

echo "hi" | xclip -selection primary

echo "hi" | xclip -selection clipboard

etc....

xclip is installed (I'm pretty familiar with Linux :-) ) and there is no output, it just moves onto the next line and my clipboard contents do not change.

Here is my linux version:

[1450] cgeorge@uaf-7 $ cat /proc/version
Linux version 2.6.18-371.1.2.el5 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)) #1 SMP Tue Oct 22 12:51:53 EDT 2013
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Alex
  • 323
  • 3
  • 8
  • 1
    Is it giving `xclip: command not found` as an error when you try the command? That means, `xclip` is not installed and you need to install it. Also, please mention what linux OS you are using and also paste the output of the commands you tried in the question. – Ramesh Apr 18 '14 at 19:36
  • And your distro? – enedil Apr 18 '14 at 22:16
  • 1
    @enedil Clearly CentOS 5. – Gilles 'SO- stop being evil' Apr 18 '14 at 22:29
  • 2
    Does `xsel -b` work? (It should be equivalent to `xclip -selection clipboard`.) Run `echo wibble | strace -o copy.strace xclip -selection clipboard` and `strace -o paste.strace xclip -selection clipboard -o -` and post the resulting traces. – Gilles 'SO- stop being evil' Apr 18 '14 at 22:31
  • xsel is not installed. The first trace gives no output, the second trace gives (only) "wibble" as output. My clipboard contents stay the same in both cases. – Alex Apr 19 '14 at 04:24
  • What did you try to say it doesn't work? What's the outcome (something else pasted, nothing pasted when you query the clipboard selection) – Stéphane Chazelas Apr 19 '14 at 06:59
  • After `echo hi | xclip -sel c`, is `xclip` running or is something else stealing the selection? Can you identify the source of the selection? Do you have a clipboard manager running? – Stéphane Chazelas Apr 19 '14 at 07:00
  • xclip seems to run, it is installed and I can run it in verbose mode (no useful output). It just doesn't put anything in the clipboard. I am running over SSH from a mac, but it still works about 40% of the time; I just don't understand why it doesn't work all the time. Any alternative ways to do this would be fine too.... – Alex Apr 19 '14 at 21:09

1 Answers1

6

X doesn't really have a "clipboard" by default. Selections are managed by the application that "owns" them, and if you want to copy or paste a selection, this is done by communication between both applications, which means the other application that holds the selection must still be running.

There is however a method to take over a selection, so there are generic clipboard applications like xclipboard, which allow other applications to "send" a XA_CLIPBOARD selection.

So, (1) either run xclip with option -l so it keeps running until a second application pastes successfully (that can require several communication rounds, so -l 1 can fail), or (2) run a clipboard manager, and use -selection XA_CLIPBOARD.

You also said "you're clipboard contents don't change", but it's not really clear which "clipboard" you mean, and how the checked that.

dirkt
  • 31,679
  • 3
  • 40
  • 73