LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-27-2008, 05:04 AM   #1
santosh045
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Rep: Reputation: 0
Red face How to store the text (selected my mouse button) as a string into a variable?


Hell all,
I want to write a shell script where i will be using the text copied (when a text is selected by mouse button,it gets copied) by mouse.
I just want to know how to store that copied text or string into a variable.

I don't know how to do that.
so you peoples help are required.
plz give the suggesions.

thanx
 
Old 09-27-2008, 05:56 AM   #2
niceguy_81333
Member
 
Registered: Mar 2008
Location: India
Distribution: RHEL5
Posts: 34

Rep: Reputation: 15
hi
I think "paste" command should work for you.
rgds
bil
 
Old 09-27-2008, 07:04 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,310
Blog Entries: 54

Rep: Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860
AFAIK the selected text gets copied to some buffer and as such 'paste' wouldn't be able to retrieve it from that buffer automagically?..
 
Old 09-27-2008, 09:26 AM   #4
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
if you are in "terminal" and you highlight some text at the cli, then it is on the clipboard.
To paste the contents of the clipboard, either "Right Click" or Center Click". This seems to work at the cli as well as in an editor where you would be creating a script
 
Old 09-27-2008, 01:37 PM   #5
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
You might try a prgram called "xclip" which provides a command line interaface to the X clipboard. It can write clipboard text to/from a file so it should be possible add some scripting that would set a shell variable to the clipboard text. Who knows what would happen however if you had an image or something currently on the clipboard?
 
Old 09-29-2008, 12:11 AM   #6
santosh045
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Red face

hello all,
i often have to open files with gvim.
for that i first select the file name with mouse.then at the terminal command promt i write gvim and then press mouse middle button.after that hitting the enter will open the file.

i want to write a shell sript and will assign a key combination to that script.
then after selecting the text if i hit the key combination it will open the file.life will become easier for me.

shell script will be like below:


#!/bin/csh

$filename=<here will be the command or procedure which will return the slected text with mouse button>
gvim $filename


I think now my problem will get understood by everyone.

so plz suggest any method so that i can take the selected text into the variable.

regards
santosh
 
Old 09-29-2008, 12:35 AM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Yep, you want to use either xclip, as mentioned above, or xsel, which does pretty much the same thing. I prefer xsel myself because it seems to do a more reliable job in some cases.

But in this case, with either one you'll simply want to output the "primary" selection (which is the default value) to the script. You don't even need to use a variable; you can output it straight to the command itself.

Code:
gvim "$(xsel -o)"

or

gvim "$(xclip -o)"
Indeed, in most cases you don't even need a script. You can create a simple menu shortcut and put this line directly in the shortcut command line. Do note that if you don't have a proper filename in the selection buffer, gvim will still open up anyway.

Last edited by David the H.; 09-29-2008 at 12:38 AM.
 
Old 09-29-2008, 01:59 AM   #8
santosh045
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Original Poster
Rep: Reputation: 0
when i type xsel on comman prompt,it says
xsell:command not found

same with xclip


so the above technique will not work.
is there any other method or i should stop doing such thing.

suggest plz

regards

santosh
 
Old 09-29-2008, 02:32 AM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You need to install the program(s) first. They don't come standard.

They should be available in the installable software repositories of your distro, whatever that is.
 
Old 09-29-2008, 07:09 AM   #10
santosh045
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Original Poster
Rep: Reputation: 0
hi

thanks for u people's reply.
i got to know many things

regards
santosh
 
  


Reply

Tags
scripting, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: removing a variable substring from a string variable in sh script gnparsons Programming 2 06-04-2008 05:21 PM
How to store text(strings) in a 2D character array reading from a text file(C++) bewidankit Programming 3 02-14-2008 07:08 AM
Bash store last line from displayed text output in a variable carl0ski Programming 1 01-16-2007 03:38 AM
Mutlipe text/button form, one submit button bappreacher Programming 8 06-27-2006 08:07 AM
middle mouse button is paste.. but what if i dont have a mid mouse button? kublador Linux - Newbie 4 09-02-2003 08:59 AM


All times are GMT -5. The time now is 11:32 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration