bash 将 shell 脚本输出复制到剪贴板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4023703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy shell script output to clipboard
提问by Vamsi Krishna B
Is there any easy way to implement the copy to clipboard option from the output of a shell script ?
有没有什么简单的方法可以从 shell 脚本的输出中实现复制到剪贴板选项?
回答by paxdiablo
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.
第一个进入鼠标剪贴板,第二个进入“普通”剪贴板。
回答by Mau
You can use pbcopy
which is native for Mac OS.
您可以使用pbcopy
Mac OS 原生的。
Try this command:
试试这个命令:
echo "variable" | pbcopy
it will copy the string "variable" into your clipboard.
它会将字符串“变量”复制到剪贴板中。
回答by dogbane
回答by Markus Zeller
If you do that on Windows 10 LXXS Ubuntu bash you can do
如果您在 Windows 10 LXXS Ubuntu bash 上执行此操作,则可以执行此操作
echo "What so ever..." |clip.exe
回答by Michael Martin
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