2

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

But instead, if I write a file,

bar.sh

#!/bin/sh
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?

1 Answer 1

6

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

-selection
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?

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .