Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I access the Shift-Insert (paste) clipboard from a script? You can see what I use here.

Edit: A demonstration how it works, with xclip:

echo hello | xclip -selection secondary
xclip -o -selection secondary

Edit 2: Just implemented the solution below. This will make my life so much easier so I thought I'd share it.

First, the script pst:


echo -n `xclip -d ":0" -o -selection clipboard`

then, in .emacs:

(defun pst ()
 "Inserts the X clipboard (xclip -d :0 -o -selection clipboard) at
point. `M-1' (the '(1)) to insert in the current buffer."
  (shell-command "pst" '(1))
  (end-of-line) )

Now, in any tty, paste with pst, in Emacs (anywhere, but specifically in a tty, as in X, you already have Shift-Insert) M-x pst.

share|improve this question
up vote 5 down vote accepted

xclip will allow you to access the PRIMARY, SECONDARY, and CLIPBOARD selections, choosing which one with the -selection option.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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