1

How do you access the (windows) clipboard in WSL so that you can pipe it into commands, use it as stdin, etc.?

There's more than enough answers about how to write to the clipboard. But I couldn't find any specifically about reading from it.

For what it's worth: I'm answering my own question. Hopefully this saves others time in the future.

1 Answer 1

4
alias pbpaste="powershell.exe -noprofile Get-Clipboard" alias pbcopy="clip.exe" 

You can put something like that in your .bashrc file or run the commands directly.


I learned the answer from this question: Linux clipboards, including with WSL consoles But, it is not asking the same thing and after 10 minutes of googling, I still can't find a direct answer to my question.

3
  • for getting the contents of the clipboard, what you call pbpaste, xclip -o -sel clip is shorter and works better for me Commented Apr 19, 2024 at 18:40
  • @KaiCarver Thanks. Works better in what sense? Commented Apr 20, 2024 at 0:14
  • I wish I knew exactly. My impression was other ways messed up accents, I don't understand why. Anyway, problem solved, thank you! Not to mention using xclip feels more unixy than calling that uh, unwieldy powershell.exe command line. Commented Apr 25, 2024 at 13:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.