Skip to content
Advertisement

Pipe to/from the clipboard in a Bash script

Is it possible to pipe to/from the clipboard in Bash?

Whether it is piping to/from a device handle or using an auxiliary application, I can’t find anything.

For example, if /dev/clip was a device linking to the clipboard we could do:

JavaScript

Advertisement

Answer

2018 answer

Use clipboard-cli. It works with macOS, Windows, Linux, OpenBSD, FreeBSD, and Android without any real issues.

Install it with:

JavaScript

Then you can do:

JavaScript

If you want, you can alias to cb by putting the following in your .bashrc, .bash_profile, or .zshrc:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement