I am incredibly sorry if this is a duplicate. This is something that I have had very little success with determining while searching the googles:
https://www.google.com/search?q=difference+between+%24_+and+!%24
The best that I can figure is that this !$
is preferred for making your work more evident in command history and in shell output.
Example:
02:05 Mac Shell: ~/>$ cat $_
this is a file called something
02:06 Mac Shell: ~/>$ cat !$
cat $_
this is a file called something
02:06 Mac Shell: ~/>$ cat something
this is a file called something
02:06 Mac Shell: ~/>$ cat !$
cat something
this is a file called something
02:06 Mac Shell: ~/>$ echo "This is a string"
This is a string
02:08 Mac Shell: ~/>$ echo !$
echo "This is a string"
This is a string
02:08 Mac Shell: ~/>$ echo "This is a string"
This is a string
02:08 Mac Shell: ~/>$ echo $_
This is a string
02:08 Mac Shell: ~/>$ history | tail
857 30/12/16 02:05:55 vim something
858 30/12/16 02:06:07 cat $_
859 30/12/16 02:06:12 cat $_
860 30/12/16 02:06:36 cat something
861 30/12/16 02:06:40 cat something
862 30/12/16 02:08:18 echo "This is a string"
863 30/12/16 02:08:26 echo "This is a string"
864 30/12/16 02:08:32 echo "This is a string"
865 30/12/16 02:08:37 echo $_
866 30/12/16 02:09:14 history | tail
02:09 Mac Shell: ~/>$
Question:
Are there any other differences that I should know about?
Edit:
antak brought it to my attention that $_ is great for one liners whereas !$ is not:
02:35 Mac Shell: ~/>$ echo bar && echo foo$_
bar
foobar
02:35 Mac Shell: ~/>$ echo bar && echo foo!$
echo bar && echo foofoo$_
bar
foofoobar
02:35 Mac Shell: ~/>$