10

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 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)) #1 SMP Tue Oct 22 12:51:53 EDT 2013
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, 2014 at 19:36
  • And your distro?
    – enedil
    Apr 18, 2014 at 22:16
  • 1
    @enedil Clearly CentOS 5. Apr 18, 2014 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. Apr 18, 2014 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, 2014 at 4:24

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.