If I do echo foo | xclip -i in the terminal and then Ctrl + V, I get foo.

But instead, if I write a file,


echo bar | xclip -i

and run ./bar.sh in the terminal, the clipboard content doesn't become "bar" as I would expect.

Why? And how do I make it do to so?

I managed to do it changing the line echo bar | xclip -i to echo bar | xclip -selection c, but why does this way work and the other doesn't?


When you use the command

echo bar | xclip -i

xclip stores the text in its primary register, which is accessible with the middle mouse button. from man xclip

specify which X selection to use, options are "primary" to use XA_PRIMARY (default), "secondary" for XA_SECONDARY or "clipboard" for XA_CLIPBOARD

When you use

echo bar | xclip -selection c

bar is being captured in xclip's clipboard register - I'm guessing c is an alias for clipboard.
Its strange the echo bar | xclip -i then Ctrl + v command worked - It doesnt for me. I wonder if you had foo in your clipboard from a previous command?

  • I got "The program 'xclip' is currently not installed." on standard Ubuntu 16.04 (Xenial Xerus). Why would it not be installed by default? – Peter Mortensen Sep 12 '16 at 17:47

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.