When I create scripts, I use the xclip command to copy a variable to the clipboard, so I can paste it using CTRL+V or automate my script to paste it with xdotool. The command that I use to copy a variable to the clipboard is this one:

echo -n "$clipboard" | xclip -selection clipboard

It works fine for pasting with CTRL+V... However, many times I want to paste things on a terminal window and only Shift+Insert works for that. For some reason xclip doesn't copy variables to the clipboard that Shift+Insert uses, it only happens when I copy some text manually with CTRL+C. Does anyone know if there's a way of programmatically copying a variable to the same clipboard that Shift+Insert uses?

1 Answer 1


Shift+Insert uses the XA_PRIMARY selection. So:

echo -n "$clipboard" | xclip -selection primary

or just

echo -n "$clipboard" | xclip

(since XA_PRIMARY is the default).

  • 1
    or, to save the echo call and the pipe, just: <<<"$clipboard" xclip
    – dessert
    Commented Jun 8, 2019 at 20:42

You must log in to answer this question.

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