它是可能的管道到/从剪贴板在Bash?

无论是连接到设备手柄还是使用辅助应用程序,我都找不到任何东西。

例如,如果/dev/clip是一个连接到剪贴板的设备,我们可以这样做:

cat /dev/clip        # Dump the contents of the clipboard
cat foo > /dev/clip  # Dump the contents of "foo" into the clipboard

当前回答

在Linux中,这是可行的:

cat filename | xclip

其他回答

复制和粘贴到剪贴板在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)存在。

我只是在我的KDE环境中搜索相同的东西。

请随意使用剪贴和剪贴。

KDE:

> echo "TEST CLIP FROM TERMINAL" | clipcopy
> clippaste
TEST CLIP FROM TERMINAL

在Windows子系统for Linux (WSL)上,您可以使用clip.exe复制到剪贴板:

cat file | clip.exe

请记住使用|管道命令。而不是>命令,因为这将不起作用。

安装xcopy实用程序,当你在终端中,输入:

Copy

Thing_you_want_to_copy | xclip -selection c

粘贴

myvariable=$(xclip -selection clipboard -o)

我注意到很多答案推荐pbpaste和pbcopy。如果您喜欢这些实用程序,但由于某种原因它们在存储库中不可用,那么您总是可以为xcopy命令创建别名,并将它们称为pbpaste和pbcopy。

alias pbcopy="xclip -selection c"
alias pbpaste="xclip -selection clipboard -o"

所以它看起来是这样的:

Thing_you_want_to_copy | pbcopy
myvariable=$(pbpaste)

一个名为doug的用户在我的评论中给出了一个答案。既然我发现它很有帮助,我决定在回答中重申一遍。

确保使用别名xclip="xclip -selection c" 否则你将无法使用Ctrl+v进行粘贴。

例子: 执行echo -n test | xclip命令后,Ctrl+v将粘贴test