它是可能的管道到/从剪贴板在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
当前回答
在Windows上(使用Cygwin)尝试 Cat /dev/clipboard或echo "foo" > /dev/clipboard如本文所述。
其他回答
这个函数将测试存在哪些剪贴板并使用它。
要验证复制粘贴到你的shell,然后调用函数clippaste:
clippaste () {
if [[ $OSTYPE == darwin* ]]
then
pbpaste
elif [[ $OSTYPE == cygwin* ]]
then
cat /dev/clipboard
else
if command -v xclip &> /dev/null
then
xclip -out -selection clipboard
elif command -v xsel
then
xsel --clipboard --output
else
print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
return 1
fi
fi
}
下面是一个可以在多个平台上使用的Bash脚本,用于读取剪贴板。
如果您要添加功能(例如,更多的平台),请在这里编辑脚本。
#!/bin/bash
# WF 2013-10-04
#
# Multi-platform clipboard read access
#
# Supports
# Mac OS X
# Git shell / Cygwin (Windows)
# Linux (e.g., Ubuntu)
#
# Display an error
#
error() {
echo "error: $1" 1>&2
exit 1
}
#
# getClipboard
#
function getClipboard() {
os=`uname`
case $os in
# Git Bash (Windows)
MINGW32_NT-6.1)
cat /dev/clipboard;;
# Mac OS X
Darwin*)
pbpaste;;
# Linux
Linux*)
# Works only for the X clipboard - a check that X is running might be due
xclip -o;;
*)
error "unsupported os $os";;
esac
}
tmp=/tmp/clipboard$$
getClipboard >$tmp
cat $tmp
# Comment out for debugging
rm $tmp
你可以使用大量的剪贴板。我想你可能是一个Linux用户,想把东西放到X Windows主剪贴板中。通常,您想要与之对话的剪贴板有一个实用程序可以让您与之对话。
在X的情况下,有xclip(和其他)。xclip -selection c将数据发送到剪贴板,在大多数应用程序中使用Ctrl + c, Ctrl + V。
如果你在Mac OS X上,有pbcopy。例如,cat example.txt | pbcopy
如果你在Linux终端模式下(没有X),那么查看有剪贴板的gpm或Screen。试试Screen命令readreg。
在Windows 10+或Cygwin下,使用/dev/clipboard或clip。
Linux中有不同的剪贴板;X服务器有一个,窗口管理器可能有另一个,等等。没有标准的设备。
哦,是的,在CLI中,屏幕程序也有自己的剪贴板,就像Emacs和vi等其他一些应用程序一样。
在X中,您可以使用xclip。
你可以检查这个线程的其他可能的答案: http://unix.derkeiler.com/Newsgroups/comp.unix.shell/2004-07/0919.html
Try
xclip
xclip - command line interface to X selections (clipboard)
man