On Mon, Aug 18, 2008 at 05:35:44PM +1000, Amos Shapira wrote: > Hello, > > I have this long command line which I keep changing multiple instances > of host names in it: > > # rm -f redo-afn2-dev.out; ./redo.sh afn2-dev & jobs -x tail --pid > %./redo.sh -F -n +0 redo-afn2-dev.out > > I use CentOS 5 and Bash as my interactive shell. > > The problem is that just *sometimes* (most of the time it's in the > history already so no need) I want to use the last such sequence and > replace all the host name occurances by another host. > > Using history substitution, I can do something like: > > # !rm:gs/afn2/portal2/ > > and get it done. > > But the problem is that in order to do this, I need to search for the > last relevant command in the history, which I use "incremental search > backwards" for (Ctrl-R). > > But once the wanted command is the current one - I can't use the > history substitution on it. > > I found that I can refer to the current command with "!#:", so it'll look > like: > > # rm -f redo-afn2-dev.out; ./redo.sh afn2-dev & jobs -x tail --pid > %./redo.sh -F -n +0 redo-afn2-dev.out!#:gs/afn2/portal2/ > > Then I can type M-C-e (alt-control-e) to copy the command line as it > was typed so far into another version with the history substitution > done on it, BUT - that leaves me with two copies of the line: > > # rm -f redo-afn2-dev.out; ./redo.sh afn2-dev & jobs -x tail --pid > %./redo.sh -F -n +0 redo-afn2-dev.outrm -f redo-afn1-dev.out; > /redo.sh afn1-dev & jobs -x tail --pid %./redo.sh -F -n +0 > redo-afn1-dev.out > > (notice the "...dev.outrm -f..." in the middle of that last line). > > Does anyone know how can I achieve the same effect without having to > go back to the middle of the line and carefully remove the "old" copy? > > Maybe a way to tell the shell - "ok, I like the command I found, just > make it the last in the history without executing it", something that > can be done with history-substitution ":p" modifier, then I can get > back to using "!!:gs///". > > I couldn't find a solution in bash's manual or FAQ.
Here's a different way to do that: Ctrl-R # search for the command. Find it. set -o vi Esc #to get into command mode v #edit the command in VISUAL and execute -- Tzafrir Cohen | [EMAIL PROTECTED] | VIM is http://tzafrir.org.il | | a Mutt's [EMAIL PROTECTED] | | best ICQ# 16849754 | | friend ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]