17

Imagine I do:

echo $PATH

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

Any thoughts?

P̲̳x͓L̳
  • 3,615
  • 3
  • 29
  • 37
elelias
  • 4,552
  • 5
  • 30
  • 45

1 Answers1

30

Depends. Linux, Mac or Windows?

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

Copy example (mac):

echo $PATH | pbcopy

Paste Example (mac):

echo "$(pbpaste -Prefer txt)"

Linux uses X which has multiple copy-paste buffers (somewhat akin to the clipboard, but a little more involved).

You can use a little application like XSel to copy/paste, The command would be used in the same form as the pbcopy/pbpaste

Copy:

echo $PATH | xsel --clipboard

'paste':

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

For windows, you can use an app like clip, which allows the same copy/paste functionality

Copy:

set %PATH% | clip

I generally use Linux/Unix so I don't have the equivalent for pasting from the clipboard on Windows.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • thanks a lot for your answer. I am also running on Linux. I'll put this into use immediately. – elelias May 11 '12 at 10:08
  • 5
    You can also use [`xclip`](https://github.com/l0b0/tilde/commit/217c281abfbed48ee0c19c4b533f2aa9d5724429) – l0b0 May 15 '12 at 08:35