Re:The most useful thing in bash
by dllthomas on Wednesday April 17, 2013 @03:06PM
(#5566384)
$_ is a variable for the same thing. The only difference winds up being the effect on the current line's result in your history: !$ is replaced while $_ stays $_ and so its meaning will change if you run the same command later, which can be what you want or not, depending.
[ Parent
| on HN ]
Re:The most useful thing in bash
by scott_karana on Wednesday April 17, 2013 @03:35PM
(#5566577)
You're right in this specific case, but there are other useful ! arguments, so it's worth learning both.
It's the "Event Designators" in the bash manpage for those who are interested.
Oh, I didn't mean "You should use $_ instead", just "$_ is also useful."
As I tried to indicate, you should ideally use whichever will make more sense in your history later. If the command you're typing should always be applied to that file, which happened to be the last argument of the previous command this time, then use !$; if the command you're typing should always be applied to the last argument of the previous command, and it just happened to be that file this time, use $_.