它是可能的管道到/从剪贴板在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();
其他回答
在Linux中,这是可行的:
cat filename | xclip
安装
# You can install xclip using `apt-get`
apt-get install xclip
# or `pacman`
pacman -S xclip
# or `dnf`
dnf install xclip
如果你没有apt-get、pacman或dnf,源代码可以在sourceforge上找到。
设置
Bash
在~ /。bash_aliases,添加:
alias setclip="xclip -selection c"
alias getclip="xclip -selection c -o"
不要忘记使用。~ /。Bash_aliases或重新启动配置文件。
Fish
在~ / . config /鱼/配置。鱼,添加:
abbr setclip "xclip -selection c"
abbr getclip "xclip -selection c -o"
不要忘记通过重新启动终端来重新启动fish实例,以便应用更改。
使用
你现在可以使用setclip和getclip,例如:
$ echo foo | setclip
$ getclip
foo
Linux中有不同的剪贴板;X服务器有一个,窗口管理器可能有另一个,等等。没有标准的设备。
哦,是的,在CLI中,屏幕程序也有自己的剪贴板,就像Emacs和vi等其他一些应用程序一样。
在X中,您可以使用xclip。
你可以检查这个线程的其他可能的答案: http://unix.derkeiler.com/Newsgroups/comp.unix.shell/2004-07/0919.html
在Windows子系统for Linux (WSL)上,您可以使用clip.exe复制到剪贴板:
cat file | clip.exe
请记住使用|管道命令。而不是>命令,因为这将不起作用。
在macOS系统中,请使用pbpaste。
例如:
更新剪贴板
pbpaste | ruby -ne ' puts "\|" + $_.split( )[1..4].join("\|") ' | pbcopy