4 ms·
An arguably better (and slightly more portable) way to accomplish this is the special variable $_ , which expands to the last argument of the previous command.
by kps 14y ago
An arguably better (and slightly more portable) way to accomplish this is the special variable $_ , which expands to the last argument of the previous command. Since $_ is a variable rather than a history substitution, it still works when there is no command history (e.g. in scripts) and allows all the usual variable expansion forms, for example ${_##*/} to extract the last path component.
- crusso 14y agoThat's good to know, although !$ is easier to type since you only need to depress the right shift key, whereas yours requires a quick shift on the opposite side. Makes a big difference when you're trying to quickly type "rm -rf !$" as root. :)
- garethadams 14y agoI don't think I'd type `rm -rf [anything]` quickly as root
- crusso 14y agoHence the smiley. Was a joke.
- seanp2k2 14y agoAs a righty, I rarely ever use the right shift key. Also, check it: $ cd /happily/tabbing/out/some/really/deep/path/ooh/dear/maybe/its/java/WAIT_A.file bash:> 'WAIT-A.file' is not a directory $ nano $_ (opens file)