LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 05-09-2015, 03:32 AM   #1
Rezney
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Rep: Reputation: 1
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...
 
Old 05-09-2015, 04:33 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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,].
 
Old 05-09-2015, 02:53 PM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,639

Rep: Reputation: 2653Reputation: 2653Reputation: 2653Reputation: 2653Reputation: 2653Reputation: 2653Reputation: 2653Reputation: 2653Reputation: 2653Reputation: 2653Reputation: 2653
you can send the output to standard output " >"
for example the "help" option in most programs
Code:
gcc --help > ~/gcc-help.txt
 
Old 05-10-2015, 02:24 AM   #4
Rezney
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Original Poster
Rep: Reputation: 1
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.
 
Old 05-10-2015, 05:14 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,800

Rep: Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568
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.
 
Old 05-11-2015, 01:50 PM   #6
Rezney
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Original Poster
Rep: Reputation: 1
So I did not find a solution that would suit me but thanks for your support anyway.
Cheers!
 
Old 05-11-2015, 02:13 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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.
 
Old 05-11-2015, 02:28 PM   #8
Rezney
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Original Poster
Rep: Reputation: 1
Sorry I did not provide all info. Only terminal without mouse available.
 
Old 05-11-2015, 03:06 PM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Something at https://www.digitalocean.com/communi...on-a-linux-vps perhaps?
 
1 members found this post helpful.
Old 05-12-2015, 09:59 AM   #10
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: One main distro, & some smaller ones casually.
Posts: 5,667

Rep: Reputation: Disabled
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.
Old 05-14-2015, 09:16 AM   #11
Rezney
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Original Poster
Rep: Reputation: 1
Thanks for your input guys.
The script way might be closest to my idea.

I am marking this thread as solved.
 
  


Reply


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Editing PDF from CLI with shell scripts hamtavs Linux - Software 1 04-27-2008 12:35 PM
How to turn the screen sideways (CLI and X) ie rotate output 90 degrees. logbot Linux - Hardware 1 09-28-2007 03:03 PM
How can my collegues view my CLI commands (including the output) in real time ? markraem Linux - General 1 09-25-2007 08:14 AM
CLI....ls (or similar command)...formatting output Basslord1124 Linux - Newbie 2 02-27-2005 05:13 PM
Creating and editing files with CLI TheDirtyPenguin Linux - Software 2 02-02-2005 12:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration