6 ms·
I really like '!$' and '!:1' in bash. '!$' holds the last argument of the last command and '!:n' holds the nth argument. $ cd /big/long/path/to/this.txt Oops $
by endur 12y ago
I really like '!$' and '!:1' in bash. '!$' holds the last argument of the last command and '!:n' holds the nth argument.
$ cd /big/long/path/to/this.txt
Oops
$ vim !$
- 458QxfC2z3 12y agoIf using readline (emacs) keybindings, press Alt and period for the same effect as !$.
- DougMerritt 12y agoIt should be noted for onlookers that this is the abbreviated form; !-3:4 goes back to the third-to-last command and refers to its fourth argument, and similarly !-3:$ is its last argument. It's also apparently not universally known that bash has csh-style (similar to sed) editing, so "s^foo^bar" will repeat the previous command with "bar" substituted at for bar. So "ls foo" becomes "ls bar". Similarly with !-3:s^foo^bar I freely mix these things with readline-editing, depending on what needs to be done. Since csh gets a lot of disrespect these days, to give credit where due: these are all Bill Joy features from the original csh -- it's a good thing that bash borrowed innovations from various shells beyond Bourne shell and ksh. Historical footnote: We donated code to him to do readline-style editing circa 1978, but he said raw mode was bogging down the pdp 11 too much. Systems were a bit slower back then.