Search code examples
bashcommand-history

Bash history: real life example for & modifiers


I am looking learning new tricks in bash command history manipulation, in this page http://www.gnu.org/software/bash/manual/html_node/Modifiers.html#Modifiers. I see & modifiers.

when I try !!:& is not recalling previous substitution. Can you help to understand this with real example?


Solution

  • First command:

    $ echo abcdabcd
    abcdabcd
    

    Replace cd with gf. Note that only the first occurrence is replaced

    $ !!:s/cd/gf
    echo abgfabcd
    abgfabcd
    

    Repeat the substitution

    $ !!:&
    echo abgfabgf
    abgfabgf