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 -iand 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
When you use the command
echo bar | xclip -ixclip 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 cbar 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?