Replace all string matches from previous command in bash

Snippet

$ !!:gs/replacethis/withthis/

gs = global replace

Works only with bash version 3 or greater:

bash-3.2$ bash --version 
GNU bash, version 3.2.57
$ echo oneone
oneone
$ !!:gs/one/two/    # Repeats last command; substitutes 'one' --> 'two'.
twotwo

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.