Copy to clipboard using Bash for Windows

If you would like to have something more 'easy' to use, you can add the commands from @reker to your ~/.bashrc file (if you use zsh, you have to put it in the ~/.zshrc file).

I added these two lines to my file:

alias paste="powershell.exe -command \"Get-Clipboard\""
function clip { "$1" | clip.exe;}

I use clip as a function, so I can use the command linux like ('command' 'use this for command'). If you would prefer the alias way, you can add something like

alias clip=clip.exe

than you don't have to write the .exe all the time.

Don't forget to run the command

source ~/.zshrc

after you saved the file. Otherwise the changes are only applied after a restart of your console.


In Build 14393 or later, if you want to copy something to clipboard in WSL console, just add '.exe' to what you do in Windows cmd.

echo "aaa"|clip.exe

To read from clipboard:

powershell.exe -command "Get-Clipboard"

In order to copy non-ascii characters (other languages), I had to do this:

echo 'αβψδεφγ' | iconv -f utf-8 -t utf-16le | clip.exe

utf-16le excludes the preceeding BOM so you can paste it back