我经常发现自己处于以下情况:
mv picture /very/long/path/favicon.ico
cd !$
Run Code Online (Sandbox Code Playgroud)
第二个命令失败(如预期),因为!$是Not a directory。有没有一些 bash 历史替换魔法可以带我去/very/long/path?
!$:h完全符合要求:
mv picture /very/long/path/favicon.ico
cd !$:h
Run Code Online (Sandbox Code Playgroud)
来源:man bash,查找字符串trailing filename。