[ale] Commandline history substitution (was re Bash shell ALE-NW)

David S. Jackson deepbsd at earthlink.net
Fri Jun 21 17:42:14 EDT 2002



I want some feedback on whether my hypothesis is right on using command
line history editing.

in 

$ !579:2:s/foo/bar/

Does the :2: refer to the second positional parameter or not?  What's
the consensus?  Inquiring minds need to know.  :-)

> > Here is the answer to the shell history problem:
> > 
> > >!579:2:s/ux//
> > 
> > Which if the 579th command was:
> > >ps auxw | grep dhurst | awk '{print($2)}'  |  xargs kill -HUP
> > 
> > then what you would get would be:
> > 
> > >ps aw | grep dhurst | awk '{print($2)}'  |  xargs kill -HUP
> 
> Dow, this is such a good question, and I hadn't seen this prior to last
> night!  Highly cool.
> 
> > Am I right?  
> 
> As I read the man page, you could simply go
> 
>   you at host]$ !579:s/ux//
> 
> and that would give you
> 
>   ps aw | grep dhurst | awk '{print($2)}' | xargs kill -HUP
> 
> Which is what you want, I think.  But if you go 
> 
>   !579:N:s/string1/string2/
> 
> I think you're saying "just execute the Nth positional argument as a
> command in history command 579 and substitute string1 for string2".  I
> think you're telling bash to ignore the rest of the command line and
> treat the Nth positional variable as a command in itself.
> 
> Example:
> 
>   you at host]$ echo one two three four
>   one two three four
>   you at host]$ !!:4:s/our/lip/
>   flip
>   bash: flip: command not found
>   you at host]$ 
> 
> On the other hand, let's say you had an ambiguity or error you wanted to
> correct, like:
> 
>   you at host]$ echo one two two three four
>   one two two three four
>   you at host]$
> 
> Obviously, you want to remove one of the two "two's" from the string.
> But how?  Rather than try to tell bash which positional variable to
> substitute, you could try some other regular expression, like:
> 
>   you at host]$ !!:s/two two/two/
>   echo one two three four
>   one two three four
>   you at host]$
> 
> or 
> 
>   you at host]$ !!:s/two //
>   echo one two three four
>   one two three four
>   you at host]$
> 
> I think you could get as sophisticated in your regex as you needed in
> order to accomplish the same thing.  
> 
> I could easily be wrong here, but I think this is what I'm seeing.
> 
> 
> -- 
> David S. Jackson                        dsj at dsj.net
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> I don't deserve this award, but I have arthritis and
> I don't deserve that either.  -- Jack Benny
> 
> ---
> This message has been sent through the ALE general discussion list.
> See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
> sent to listmaster at ale dot org.


-- 
David S. Jackson                        dsj at dsj.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Life is divided into the horrible and the miserable.
		-- Woody Allen, "Annie Hall"

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list