From Bash Manual > History Expansion:
Event Designator
! Start a history substitution, except when followed by
a blank, newline, carriage return, = or ( (when the
extglob shell option is enabled using the shopt builtin).
!n Refer to command line n.
Word Designators
$ The last word. This is usually the last argument, but will
expand to the zeroth word if there is only one word in the line.
So, !$
just repeats the last word from previous command
Example:
$ echo Unix and Linux
Unix and Linux
$ echo !$
echo Linux
Linux
$ cat dir1
cat: dir1: Is a directory
$ cd !$
cd dir1
After executing command with !$
, press ↑ and you will get the result of !$
.