Tuesday, 8 January 2013

[bash] cd đến thư mục vừa tạo

hvn@hvnatvcc: ~ $ mkdir -p hello/this/is/familug/dot/org
hvn@hvnatvcc: ~ $ cd !$
cd hello/this/is/familug/dot/org
hvn@hvnatvcc: ~/hello/this/is/familug/dot/org $ pwd

!$ là `yank-last-arg`

từ man bash:

       yank-last-arg (M-., M-_)
              Insert  the  last argument to the previous command (the last word of the previous history entry).  With a numeric argument, behave exactly like yank-nth-arg.  Successive calls to yank-last-arg move back through the history list, inserting the last  word  (or  the  word  specified  by the argument to the first call) of each line in turn.  Any numeric argument supplied to these successive calls determines the direction to move through the history.  A negative argument  switches  the  direction through  the  history (back or forward).  The history expansion facilities are used to extract the last argument, as if the "!$" history expansion had been specified.