Copy shell script output to clipboard

后端 未结 6 437
灰色年华
灰色年华 2020-12-23 17:09

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

相关标签:
6条回答
  • 2020-12-23 17:27

    With WSL2 and sudo you can use this:

    echo "What so ever..." | /mnt/c/Windows/System32/clip.exe
    
    0 讨论(0)
  • 2020-12-23 17:31

    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.

    0 讨论(0)
  • 2020-12-23 17:35

    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.

    0 讨论(0)
  • 2020-12-23 17:36

    You can use the xclip command.

     echo hello | xclip
    

    Instructions for obtaining xclip are here.

    0 讨论(0)
  • 2020-12-23 17:36

    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
    
    0 讨论(0)
  • 2020-12-23 17:39

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

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

    Update

    Does also work with WSL and WSL2.

    0 讨论(0)
提交回复
热议问题