Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-09-2015, 03:32 AM
|
#1
|
LQ Newbie
Registered: Apr 2015
Posts: 16
Rep:
|
Output of a command for editing in CLI
Hi,
How do I manage to get an output of a command for editing in CLI?
Lets say that I grep some particular command from man pages and I wanted to press "arrow up" and have the command available for editing and then running?
Thanks...
|
|
|
05-09-2015, 04:33 AM
|
#2
|
Moderator
Registered: May 2001
Posts: 29,415
|
Pressing arrow up in most shells means accessing the previous command in its current history. Since you've never executed the command that's not possible without some work. BASH allows you to inject commands into history (see 'history -s') so that's not the problem. Half of the problem IMHO is receiving an arbitrary string from arbitrary output. The other half is that man pages examples are just that: examples. Apart from "simple" commands that don't require switches or command line arguments those examples may either not work on your system or even b0rk it completely. So I wouldn't recommend doing this in the first place and not even if you're a seasoned Linux admin. Alternatively you could start your shell session by running everything inside screen (unless you can use mouse paste actions obviously) and copy / paste with CTRL+A,[ / CTRL+A,].
|
|
|
05-09-2015, 02:53 PM
|
#3
|
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,639
|
you can send the output to standard output " >"
for example the "help" option in most programs
Code:
gcc --help > ~/gcc-help.txt
|
|
|
05-10-2015, 02:24 AM
|
#4
|
LQ Newbie
Registered: Apr 2015
Posts: 16
Original Poster
Rep:
|
unSpawn thanks for you input.
John VV that was my first idea but then I would need to make it a script in order to run it, am I right?
I found something like this:
Code:
man man | grep something | source /dev/stdin
But did not find a way how to edit it before running. And I would need to grep exact line as well.
|
|
|
05-10-2015, 05:14 AM
|
#5
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,800
|
If I understood it well you want to execute some commands to construct a new command and you want to edit it using CLI. Actually the arrow up and similar keys work on the history, therefore you will never be able to push arrow up to recall a never-executed command. It looks like you need to execute it first.
What I can imagine is to start editing an empty command line - or with your initial command (that will invoke an editor, like vi), execute your prepared commands to get the result into the editor - of course you can edit it - and finally when you close that editor the new command (the actual content) will be executed.
|
|
|
05-11-2015, 01:50 PM
|
#6
|
LQ Newbie
Registered: Apr 2015
Posts: 16
Original Poster
Rep:
|
So I did not find a solution that would suit me but thanks for your support anyway.
Cheers!
|
|
|
05-11-2015, 02:13 PM
|
#7
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Generally one would use "highlight" + "middle click" for this. If you don't have a mouse and are working on a CLI-only system, then you'd probably just redirect to a file as John VV suggested, edit the command in the file, and then execute the file like a script.
|
|
|
05-11-2015, 02:28 PM
|
#8
|
LQ Newbie
Registered: Apr 2015
Posts: 16
Original Poster
Rep:
|
Sorry I did not provide all info. Only terminal without mouse available.
|
|
|
05-11-2015, 03:06 PM
|
#9
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep:
|
|
|
1 members found this post helpful.
|
05-12-2015, 09:59 AM
|
#10
|
LQ Guru
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: One main distro, & some smaller ones casually.
Posts: 5,667
Rep:
|
Using grep to extract the command into a file, then chmod +x the file into an executable script, edit it to add #! /bin/sh as the first line. then run the script, by typing ./scriptname
|
|
1 members found this post helpful.
|
05-14-2015, 09:16 AM
|
#11
|
LQ Newbie
Registered: Apr 2015
Posts: 16
Original Poster
Rep:
|
Thanks for your input guys.
The script way might be closest to my idea.
I am marking this thread as solved.
|
|
|
All times are GMT -5. The time now is 11:27 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|