Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When copying text to the clipboard, xclip provides several selection targets:

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

Is there a way to target multiple selections?

I have tried the following options

  1. echo "Hello world" | xclip -i -selection primary -selection clipboard
  2. echo "Hello world" | xclip -i selection primary | xclip -i selection clipboard
  3. echo "Hello world" | xclip -i selection primary,clipboard

but none of them worked.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I have tried the following options

echo "Hello world" | xclip -i selection primary | xclip -i selection clipboard  

You were really close there...
Add -f to the second command and it will output the same string as input for the third command:

echo "Hello World" | xclip -i -sel c -f | xclip -i -sel p

From man xclip:

-f, -filter
              when xclip is invoked in the in mode with output level set to silent (the defaults), the filter option will cause xclip to print the text piped to standard in back to standard out unmodified
share|improve this answer
    
Thanks! I am accepting this solution because: 1) It informs about an interesting feature of xclip. 2) It allows me to pipe xclip commands which is quite convenient and 3) For some odd reason, it's the only answer so far that gives a working solution in my experiments for binding copy-pipe in tmux (this is what prompted this question) –  user815423426 Mar 25 '13 at 20:18

I don't use xclip, so there may be a way to do this natively which I'm not aware of. In any case, this should work assuming your shell is bash:

echo "Hello world" | tee >(xclip -i -selection primary) >(xclip -i -selection clipboard) >/dev/null

>() is a form of process substitution. bash replaces each with the path to a file descriptor which is connected to the standard input of the program within the parentheses.

share|improve this answer
    
Thanks! Do you know if that syntax compatible with zsh too? –  user815423426 Mar 25 '13 at 17:33
    
@user815423426 As far as I know, yes. –  Chris Down Mar 25 '13 at 19:38

Your Answer

 
discard

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.