Bang dollar seems to refer to the last part of the last command line.
E.g.
$ ls -l
.... something
$ !$
-l
bash: -l command not found
I can find plenty on the dollar variables (e.g. $!
) but not on this. Any explanation?
Bang dollar seems to refer to the last part of the last command line.
E.g.
$ ls -l
.... something
$ !$
-l
bash: -l command not found
I can find plenty on the dollar variables (e.g. $!
) but not on this. Any explanation?
!$
can do what$_
does, except the fact that$_
does not store the value it returns (as its substitution) tohistory
.Here is an example.
With
!$
With
$_
More options:
That's the last argument of the previous command. From the documentation:
Remark. If you want to play around with Bash's history, I suggest you turn on the shell option
histverify
like so:(you can also put it in your
.bashrc
to have it on permanently). When using history substitution, the substitution is not executed immediately; instead, it is put in readline's buffer, waiting for you to press enter… or not!To make things precise, typing
!$
is not equivalent to typing"$_"
:!$
is really a history substitution, refering to the last word of the previous command that was entered, whereas"$_"
is the last argument of the previously executed command. You can compare both (I haveshopt -s histverify
):Also:
And also:
And also
And also
There are lots of other examples, e.g., with aliases.