如果这是重复的话,我感到非常抱歉。这是我在搜索谷歌时确定的一点点成功:
https://www.google.com/search?q=difference+between+%24_+and+!%24
我能想到的最好的结果是,!$
是首选,可以让您的工作在命令历史记录和shell输出中更加明显。
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: ~/>$
我还应该了解其他差异吗?
antak引起我的注意,$ _对于一个衬垫来说非常好,而!$则不是:
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: ~/>$