Copy shell script output to clipboard

2020-02-17 02:36发布

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

标签: bash shell
5条回答
smile是对你的礼貌
2楼-- · 2020-02-17 02:46

You can use pbcopy which is native for Mac OS.

Try this command:

echo "variable" | pbcopy

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

查看更多
男人必须洒脱
3楼-- · 2020-02-17 03:05

You can use the xclip command.

 echo hello | xclip

Instructions for obtaining xclip are here.

查看更多
叛逆
4楼-- · 2020-02-17 03:07

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:

For Mac:

printf "$YOUR_VAR" | pbcopy
查看更多
冷血范
5楼-- · 2020-02-17 03:08

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:

echo 123 | xclip
echo 123 | xclip -sel clip

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

查看更多
我命由我不由天
6楼-- · 2020-02-17 03:10

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

echo "What so ever..." |clip.exe
查看更多
登录 后发表回答