Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 15 Nov 2018, 04:59
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Passing clipboard content to bash variable
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [13 Posts]  
Author Message
fmen

Joined: 07 May 2018
Posts: 51

PostPosted: Sat 19 May 2018, 15:53    Post subject:  Passing clipboard content to bash variable  

#!/bin/bash

url = 'xclip -o -selection clipboard'
/usr/bin/palemoon url

# clipboard content is "www.my.yahoo.com"
# result: palemoon opens url.com not yahoo

# xenialpup 7.5 64bit
# Can anyone tell this newbie where I went wrong? Thanks.
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 910

PostPosted: Sat 19 May 2018, 16:17    Post subject:  

Haven't tested but maybe it should be:
Code:
url=$(xclip -o -selection clipboard)
/usr/bin/palemoon $url
Back to top
View user's profile Send private message Visit poster's website 
fmen

Joined: 07 May 2018
Posts: 51

PostPosted: Sat 19 May 2018, 16:25    Post subject:  

Thanks, but no go. Browser opens home page now. Looks like is not grabbing clipboard content.
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 910

PostPosted: Sat 19 May 2018, 16:32    Post subject:  

Then you must work with the command
Code:
url=$(xclip -o -selection clipboard)

What is the output of
Code:
echo $url
?
Alternatively
Code:
echo ${url}

Just to verify - what is the output of
Code:
xclip -o -selection clipboard
?
Back to top
View user's profile Send private message Visit poster's website 
fmen

Joined: 07 May 2018
Posts: 51

PostPosted: Sat 19 May 2018, 17:26    Post subject:  

Ok, the output of :

Code:

xclip -o -selection clipboard

and
Code:

xclip -o clipboard

Produces the clipboard url "my.yahoo.com"
Code:

echo url

produces output "url"
Code:

echo $url

produces nothing[/code][/quote][/code]
Back to top
View user's profile Send private message 
fmen

Joined: 07 May 2018
Posts: 51

PostPosted: Sat 19 May 2018, 18:03    Post subject:  

Solved!!

Even simpler is the following...

Code:

/usr/bin/palemoon $(xclip -o)
Back to top
View user's profile Send private message 
Keef


Joined: 20 Dec 2007
Posts: 922
Location: Staffordshire

PostPosted: Sat 19 May 2018, 18:14    Post subject:  

Try sending the output to a temporary text file:

Code:
xclip -o -selection clipboard > clip.txt
url=$(cat clip.txt)
echo $url


If you paste this straight into a terminal, and run it, then url will equal the above code, as it will always be the last thing copied.

[EDIT] Looks like you got a better answer anyway.
Back to top
View user's profile Send private message 
fmen

Joined: 07 May 2018
Posts: 51

PostPosted: Sat 19 May 2018, 18:41    Post subject:  

I appreciate that there are more than one way to get results. Thanks.

The reason for this exercise was to be able to write a small script that opens chromium urls in palemoon.

http://murga-linux.com/puppy/viewtopic.php?p=992577#992577
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 12965
Location: Gatineau (Qc), Canada

PostPosted: Sat 19 May 2018, 19:07    Post subject:  

Hi fmen.

I suppose that you already know that if you type an URL such as
www.my.yahoo.com in console (or you can paste it in the console with
middle-click from anywhere) and then single-left-click on it, this URL will
open in your default browser.

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
tallboy


Joined: 21 Sep 2010
Posts: 1053
Location: Oslo, Norway

PostPosted: Sat 19 May 2018, 19:44    Post subject:  

musher0, that depends on which terminal you use, and how it is set up. Traditionally, mouse clicks don't have anything to do in a term window! Mad
_________________
True freedom is a live Puppy on a multisession CD/DVD.
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 12965
Location: Gatineau (Qc), Canada

PostPosted: Sat 19 May 2018, 22:56    Post subject:  

tallboy wrote:
musher0, that depends on which terminal you use, and how it is set up. Traditionally, mouse clicks don't have anything to do in a term window! Mad

Tallboy,

you made me fall off my chair! Laughing Please explain!

Don't all Puppies come with gpm (the "general purpose mouse") installed at
/usr/sbin/gpm and /usr/lib/gpm, and activated through /etc/init.d/gpm?

Plus: this cannot be all wrong, can it?
https://wiki.archlinux.org/index.php/Copying_text_from_a_terminal

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
tallboy


Joined: 21 Sep 2010
Posts: 1053
Location: Oslo, Norway

PostPosted: Sun 20 May 2018, 18:45    Post subject:  

musher0, I use a urxvt terminal window.
I can paste previously selected text by a middle-click.
With the left button, I can select text in a terminal window by dragging, double-clicking or triple-clicking, and the text is copied.
If I click on text in the terminal, nothing happens, unless I start dragging it to select some text.
I have never been able to single-click on an url to make it open in a browser.
Neat trick, but it must create trouble if you just click to start copying some text?

_________________
True freedom is a live Puppy on a multisession CD/DVD.
Back to top
View user's profile Send private message 
hamoudoudou

Joined: 24 Jul 2014
Posts: 1467
Location: rabat

PostPosted: Tue 12 Jun 2018, 20:05    Post subject: Programming section : Click in terminal  

What i know is that previous commands are in history
if you type first your preferred sites, then use history
i ws just checking topics in this programmers forum.. Yes, really not my cup of tea..
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [13 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0594s ][ Queries: 12 (0.0141s) ][ GZIP on ]