Re: Bash history [search,] substitution, & display (not execution)

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 09/29/05


Date: Thu, 29 Sep 2005 14:37:06 -0400

On 2005-09-29, Fred Ma wrote:
> >>
> >> !251:pgs/InterestingCommand/echo/ <========*************
> >> !251:gs/InterestingCommand/echo/p
> >>
> >> In the 1st one, "gs/InterestingCommand/echo/" is appended to history
> >> entry#251 and displayed. None of the desired substitution happens.
> >> In the 2nd one, the trailing "p" gets appended to history entry#251,
> >> rather than cueing bash to display the modified command instead of
> >> executing it.
[snip]
>
> Thanks Chris.
>
> What about my interpretation of the bash man page in the
> asterisk-highlighted command above? Should I have expected it to have
> done the job?
>
> The reason I ask is because I often do want to apply the substitution
> to all history entries containing InterestingCommand, but not always.
> I often just type "history | grep InterestingCommand", look at the
> entries returned, pick one using the history invocation (!251), do a
> global substitution & print as in the asterisk-highlighted command
> above. I haven't been able to get it to work without prepending the
> whole thing with the word "echo". I'm wondering where the error is
> in my interpretation of the man page. Thanks for any comments.

man bash
   .....
   Modifiers
       After the optional word designator, there may
       appear a sequence of one or more of the following
       modifiers, each preceded by a `:'.
                  ^^^^^^^^^^^^^^^^^^^^^^

!251:p:gs/InterestingCommand/echo/

-- 
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>