它是可能的管道到/从剪贴板在Bash?
无论是连接到设备手柄还是使用辅助应用程序,我都找不到任何东西。
例如,如果/dev/clip是一个连接到剪贴板的设备,我们可以这样做:
cat /dev/clip # Dump the contents of the clipboard
cat foo > /dev/clip # Dump the contents of "foo" into the clipboard
它是可能的管道到/从剪贴板在Bash?
无论是连接到设备手柄还是使用辅助应用程序,我都找不到任何东西。
例如,如果/dev/clip是一个连接到剪贴板的设备,我们可以这样做:
cat /dev/clip # Dump the contents of the clipboard
cat foo > /dev/clip # Dump the contents of "foo" into the clipboard
当前回答
在这个线程中,有一个选项不需要安装任何gclip/xclip/xsel第三方软件。
Perl脚本(因为通常总是安装Perl)
use Win32::Clipboard;
print Win32::Clipboard::GetText();
其他回答
复制和粘贴到剪贴板在Windows (Cygwin):
See:
$ clip.exe -?
CLIP
Description:
Redirects output of command line tools to the Windows clipboard.
This text output can then be pasted into other programs.
Parameter List:
/? Displays this help message.
Examples:
DIR | CLIP Places a copy of the current directory
listing into the Windows clipboard.
CLIP < README.TXT Places a copy of the text from readme.txt
on to the Windows clipboard.
还有getclip(它可以代替Shift + Ins!)和putclip (echo oeuoa | putclip.exe将其放入clip)存在。
一种从剪贴板粘贴到文件的方法,不需要任何工具,除了echo。
转义你想要粘贴的文本中的单引号:用“\”替换所有出现的“\”并将结果复制到剪贴板。 输入echo -n ' 按Shift +插入 输入' > filename.txt 按回车键
基本上你是这样做的:
Echo -n复制“text”带“\”单引号“\”转义“> filename.txt”
即使复制的文本有新的行,它也能工作。
在macOS系统中,请使用pbpaste。
例如:
更新剪贴板
pbpaste | ruby -ne ' puts "\|" + $_.split( )[1..4].join("\|") ' | pbcopy
Try
xclip
xclip - command line interface to X selections (clipboard)
man
2018的答案
使用clipboard-cli。它适用于macOS, Windows, Linux, OpenBSD, FreeBSD和Android,没有任何实际问题。
安装方法:
npm install -g clipboard-cli
然后你可以这样做:
echo foo | clipboard
如果你愿意,你可以通过在你的.bashrc, .bash_profile或.zshrc中放入以下文件来别名cb:
alias cb=clipboard