Can I paste the result of a shell command into the clipboard?

Imagine:

echo $PATH 

in the terminal. Is it possible that the result will be automatically copied so that if I do Ctrl + y , it will be printed? As far as I understand, when Ctrl + k is executed on the terminal, the text is saved in the memory buffer that belongs to the terminal, so I think something like this should be possible.

Any thoughts?

+6
source share
1 answer

It depends. Linux, Mac or Windows?

The mac has pbcopy and pbpaste to copy and paste something from the clipboard.

Copy example (mac):

 echo $PATH | pbcopy 

Insert example (mac):

 echo "$(pbpaste -Prefer txt)" 

Linux uses X, which has several copy-paste buffers (several similar to the clipboard, but slightly more involved).

You can use a small application like XSel to copy / paste. The command will be used in the same form as pbcopy / pbpaste

Copy:

 echo $PATH | xsel --clipboard 

'paste':

 echo "$(xsel --output --clipboard)" 

For windows, you can use an application such as clip , which allows you to use the same copy / paste functions

Copy:

 set %PATH% | clip 

I usually use Linux / Unix, so I don’t have the equivalent to paste from the clipboard on Windows.

+9
source

Source: https://habr.com/ru/post/915488/


All Articles