LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-11-2010, 04:00 AM   #1
gumaheru
LQ Newbie
 
Registered: Nov 2009
Posts: 20

Rep: Reputation: 0
Bash Command Line Editor, while typing run another command before executing current?


Is there a way for me to run another command and return to the current? An example would be using vi to input a string of characters. I realize I need to check something so I back out of the input and run a shell command using ":!<shell command>". I get the output from that command and hit any key to get back to what I was previously doing in vi. Is there any known way of doing this from the command line? I use the standard emacs as my command line interpretor but if vi has this function at the command line, I'll switch.

I know everyone is going to say why? Just open another shell. But what if I am at a console? Yeah I know use screen. But what if I don't have screen installed at the time? Just picking brains.
 
Old 04-11-2010, 04:16 AM   #2
Vrajgh
Member
 
Registered: Aug 2005
Posts: 65

Rep: Reputation: 31
Do you just mean hit "Ctrl-z" to suspend a program whilst you do whatever you want in the shell and then "fg" to return to whatever you were doing?

If so, you might want to read this http://www.gnu.org/software/bash/man...ol-Basics.html

If that isn't what you want, then you may have to explain your problem again more clearly.
 
Old 04-11-2010, 02:16 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
In vi you can use Esc (to ensure you are in command mode) then :!<command> to run a command. If <command> is the command for a shell then that shell will run until you exit it when the vi session will resume.
 
Old 04-12-2010, 12:59 PM   #4
gumaheru
LQ Newbie
 
Registered: Nov 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Okay so there is a bit of misunderstanding. Here is an example of what I am trying to do. I am at a bash command line. I want to run tcpdump on a dual homed system. I start typing "tcpdump -i eth" I just realize I don't remember which nic is the nic I want to dump info for. Is there a way for me to run "ifconfig -a" without loosing what I currently have on the command line? This would help if I had a huge amount of arguments or if I was running a loop at the command line and didn't want to back out of what I currently have.

I know that I can cut and paste, put an "#" at the beginning of the line if I were to just hit "Ctrl-c" .. etc. I just don't like pulling my hand away from the home row. So from my example above, it would be like using the ":! <shell command>" in vi.
 
Old 04-12-2010, 02:39 PM   #5
Vrajgh
Member
 
Registered: Aug 2005
Posts: 65

Rep: Reputation: 31
You have set quite a challenge to do this w/o moving your hands away from the home row, but we'll see what we can do! ;-) I think you have several options!

You have alluded to inserting a comment, and a quick way to do that is "Ctrl-A # Ret". How easy that is depends on where # is on your keyboard. A quicker way is to use readline to bind a key to "insert-comment" (see here) By default this is Alt-# which is quite easy on my keyboard. If you don't like it you can change it too.

Yet another method would be to run gnu screen all the time. http://www.gnu.org/software/screen/ Then you could "alt-a c" to make a new terminal run what you want and alt-a alt-a back (and then alt-a alt-a between the two as much as you like...) I do this when I ssh into a box.

Finally if you are running on a vt of course you have the options of alt-1 alt-2 etc to get to different terminals.

If none of those are satisfactory then you are very hard to satisfy! :-D

Edit: ok you have already said you might not have screen installed... so you don't like that one, so here is another option to replace it...

Readline also has a "backwards-kill-line" which by default is bound to "c-x rubout" (for me that is ctrl-x backspace). Then do what you want and on the next line yank with ctrl-y to yank back what you deleted before. Again if you don't like the bindings you can change them.

Last edited by Vrajgh; 04-12-2010 at 02:45 PM.
 
Old 04-13-2010, 12:21 PM   #6
gumaheru
LQ Newbie
 
Registered: Nov 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks Vrajgh for your insite. I am pretty command line savy. But you know how it is. The more you know the lazier you get when it comes to inputting text at the command line. Also I know that if you can think of it, it might be possible with linux/unix. So I just had to ask.
 
  


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
hidden typing mistakes on command line stabu Linux - Software 1 03-15-2010 06:48 AM
Create typing shortcuts in command line PaulFXH Linux - General 1 07-16-2009 03:06 PM
Does bash shell parameter expansion run the risk of overflowing command line buffer? david1941 Linux - Software 1 04-28-2009 11:13 PM
Bash script run via cron not executing MYSQL command mackstar Linux - Server 4 04-23-2009 06:01 AM
bash - difference between executing program in for loop and typing each command? jlarsen Programming 14 11-10-2008 06:38 PM


All times are GMT -5. The time now is 06:00 PM.

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