2008-12-05

fun with bash

rofl...just saw this on the LPI mailing list.
$ echo !?foo?$:t:s/bar/baz/

(Just in case you're wondering: This will look for the most recent command line in the history containing the string »foo«, pick up the last word of that line, discard everything from that word except for the last filename component, and return that with the string »bar« replaced by »baz«. And just for the record, I don't use such things myself as my poor brain cannot handle them as a matter of course.)

1 comment:

Philip Paeps said...

Actually, history expansion and substitution are features of the shell I use *very* often. Especially !$ is almost a compulsion. Sensible shells - zsh, tcsh - make it much less awkward than the bloody awful shell though. With completion and editing.