将shell脚本输出复制到剪贴板

时间:2021-05-17 16:23:12

Is there any easy way to implement the copy to clipboard option from the output of a shell script ?

有没有简单的方法从shell脚本的输出实现复制到剪贴板选项?

5 个解决方案

#1


26  

That may depend on the environment you're using. With Gnome at least (I haven't tried the others but it may work), you can pipe your output as follows:

这可能取决于您正在使用的环境。至少使用Gnome(我没有尝试过其他但可能有效),您可以按如下方式输出输出:

echo 123 | xclip
echo 123 | xclip -sel clip

The first goes to the mouse clipboard, the second to the "normal" clipboard.

第一个转到鼠标剪贴板,第二个转到“普通”剪贴板。

#2


22  

You can use pbcopy which is native for Mac OSX.

您可以使用原生用于Mac OSX的pbcopy。

Try this command:

试试这个命令:

echo "variable" | pbcopy

it will copy the string "variable" into your clipboard.

它会将字符串“variable”复制到剪贴板中。

#3


5  

You can use the xclip command.

您可以使用xclip命令。

 echo hello | xclip

Instructions for obtaining xclip are here.

获取xclip的说明在这里。

#4


1  

echo prints a newline at the end as well. Incase anyone else hits the same issue, I used Mauro's approach but with the printf command so that it's just the string, no extra line:

echo也会在最后打印一个换行符。如果其他人遇到同样的问题,我使用了Mauro的方法,但使用printf命令,这样它就是字符串,没有额外的行:

For Mac:

对于Mac:

printf "$YOUR_VAR" | pbcopy

#5


1  

If you do that on Windows 10 LXXS Ubuntu bash you can do

如果你在Windows 10 LXXS Ubuntu bash上这样做,你可以做到

echo "What so ever..." |clip.exe

#1


26  

That may depend on the environment you're using. With Gnome at least (I haven't tried the others but it may work), you can pipe your output as follows:

这可能取决于您正在使用的环境。至少使用Gnome(我没有尝试过其他但可能有效),您可以按如下方式输出输出:

echo 123 | xclip
echo 123 | xclip -sel clip

The first goes to the mouse clipboard, the second to the "normal" clipboard.

第一个转到鼠标剪贴板,第二个转到“普通”剪贴板。

#2


22  

You can use pbcopy which is native for Mac OSX.

您可以使用原生用于Mac OSX的pbcopy。

Try this command:

试试这个命令:

echo "variable" | pbcopy

it will copy the string "variable" into your clipboard.

它会将字符串“variable”复制到剪贴板中。

#3


5  

You can use the xclip command.

您可以使用xclip命令。

 echo hello | xclip

Instructions for obtaining xclip are here.

获取xclip的说明在这里。

#4


1  

echo prints a newline at the end as well. Incase anyone else hits the same issue, I used Mauro's approach but with the printf command so that it's just the string, no extra line:

echo也会在最后打印一个换行符。如果其他人遇到同样的问题,我使用了Mauro的方法,但使用printf命令,这样它就是字符串,没有额外的行:

For Mac:

对于Mac:

printf "$YOUR_VAR" | pbcopy

#5


1  

If you do that on Windows 10 LXXS Ubuntu bash you can do

如果你在Windows 10 LXXS Ubuntu bash上这样做,你可以做到

echo "What so ever..." |clip.exe