user5655946
user5655946

Reputation:

Linux - How to copy a output of a command into clipboard

I'm tired of going on internet just to check up my public ip, so I've created a ip.run file :)

That's what is stored in that file:

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
cat ip.run | xclip

I run it with ./ip.run command and I successfuly get my public ip from google servers, but it is not copied to clipboard yet.. So, what I want to achive, is to copy the output of dig command into clipboard automatically.. But ofcourse what I've done so far doesn't work... I really need help on this one :P Thank you so much!

Upvotes: 1

Views: 6029

Answers (2)

der_do
der_do

Reputation: 21

In X11 you have multiple 'clipboards'.

If you select text with the mouse, you can paste that selection by using the middle mouse button.

Ctrl+c is another clipboard.

See xclip(1):

-selection specify which X selection to use, 
                   options are "primary" to use XA_PRIMARY (default), 
                    "secondary" for XA_SECONDARY or "clipboard" for XA_CLIPBOARD

Try the middle button after your command. Or use xclip -selection clipboard and then ctrl+v

With this you can do:

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}' | xclip

Then "mniddle button mousclick" in your target

OR

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}' | xclip -selection clipboard

Then got to your target and hit CTRL+V to paste the clipboard.

Upvotes: 2

Thomas Hedden
Thomas Hedden

Reputation: 467

I recommend storing the value in an environment variable. The following works for the Korn shell. If you use bash you'll have to modify it. Your command:

$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
24.62.111.99
Do this:
$ export MY_VARIABLE=`dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'`
$ print $MY_VARIABLE
24.62.111.99

Notice the back quotes `` enclosing your command.

Upvotes: 0

Related Questions