It is in the nature of bash that you can go a decade without ever figuring something out only to have your life changed by a random comment on the internet.
Is there a shortcut to reuse the result of the last command? “which java => ll $(!!)”, but the “!!” reexecutes the last command, I’d like something which doesn’t.
This is amazing! I don't think I'll use it for help (up-arrow, ctrl+w is fewer keystrokes), but I can think of many other situations where I want to substitute one word of a very long command and didn't realize it could be this easy
does the same thing. The bash manual says ^string1^string2^ is equivalent to
!!:s/string1/string2/
where / can be any delimiter, and the "final delimiter is optional if it is the last character of the event line." So, not so surprising that the third ^ is optional too.
TIL: In either of these forms, if string1 is empty, it is set to the last string1, or, "if no previous history substitutions took place, the last string in a !?string[?] search." E.g.
$ echo foofoo
foofoo
$ ^foo^
echo foo
foo
$ ^^bar
echo bar
bar
I'm looking at you, otherwise-excellent wp-cli. :-)
reply