在 Bash 脚本中通过管道传入/传出剪贴板 [英] Pipe to/from the clipboard in a Bash script
问题描述
是否可以在 Bash 中通过管道传入/传出剪贴板?
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.
例如,如果 /dev/clip
是一个链接到剪贴板的设备,我们可以这样做:
For example, if /dev/clip
was a device linking to the clipboard we could do:
cat /dev/clip # Dump the contents of the clipboard
cat foo > /dev/clip # Dump the contents of "foo" into the clipboard
推荐答案
2018 答案
使用 clipboard-cli.它适用于 macOS、Windows、Linux、OpenBSD、FreeBSD 和 Android,没有任何实际问题.
2018 answer
Use clipboard-cli. It works with macOS, Windows, Linux, OpenBSD, FreeBSD, and Android without any real issues.
安装:
npm install -g clipboard-cli
然后你可以这样做:
echo foo | clipboard
如果需要,您可以通过将以下内容放入 .bashrc
、.bash_profile
或 来为
:cb
设置别名.zshrc
If you want, you can alias to cb
by putting the following in your .bashrc
, .bash_profile
, or .zshrc
:
alias cb=clipboard
这篇关于在 Bash 脚本中通过管道传入/传出剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!