How can I pipe the output of a bash or shell command to the clip board?

5,330

Solution 1

Install xsel either through the above link or through the terminal:

sudo apt-get install xsel

To copy the output of a command use:

*command* | xsel -ib

An example:

$ drush uli | xsel -ib

You can make it simpler by editing (create it if you don't already have it with touch ~/.bash_aliases) your ~/.bash_aliases file.
Add this line to it: alias clipboard = 'xsel -ib' (you can use any name, not just clipboard).

Once you've done so you can use: *command* | clipboard

Solution 2

I use xclip.

Example:

bashscript.sh | xclip -sel clip

Solution 3

You can use xsel in just that way:

xsel -i -b >/dev/null
  • Option -i (--input) makes it read input from standard input
  • Option -b (--clipboard) makes it use the clipboard buffer instead the selection or one of the less commonly further buffers.
  • >/dev/null is hiding some annoying error message - not shure that can occur with these options set.

So, why not try

drush uli | xsel -i -b

and tell whether paste from clipboard pastes the right text!
I left out the part hiding errors for testing.

Share:
5,330

Related videos on Youtube

Rick
Author by

Rick

Updated on September 18, 2022

Comments

  • Rick
    Rick over 1 year

    In order to minimize mouse usage (accessibility and health reasons), how can I pipe the standard out to the OS clip board?

    That is, I'd like to do something like:

    $ drush uli | copy-this-to-clipbaord

    $ drush uli > copy-this-to-clipbaord

    Possible?