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 |
hi
I think "paste" command should work for you. rgds bil |
AFAIK the selected text gets copied to some buffer and as such 'paste' wouldn't be able to retrieve it from that buffer automagically?..
|
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 |
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?
|
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 |
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)" |
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 |
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. |
hi
thanks for u people's reply. i got to know many things regards santosh |
All times are GMT -5. The time now is 11:07 AM. |