Pushd 總是推送當前目錄嗎?

Pushd 總是推送當前目錄嗎?
$ pwd
/tmp/d1
$ dirs
/tmp/d1
$ pushd ../d2
/tmp/d2 /tmp/d1
$ popd
/tmp/d1
$ pwd
/tmp/d1

似乎總是pushd將當前目錄推/tmp/d1入堆棧,儘管我將其運行為pushd ../d2?

注意:http://linux.101hacks.com/cd-command/dirs-pushd-popd/

dir 指令輸出的第一個目錄總是目前目錄,而不是堆疊中的內容。

答案1

pushd並不總是推送當前目錄。來自bash'man頁面:

   pushd [-n] [+n] [-n]
   pushd [-n] [dir]
          Adds  a directory to the top of the directory stack, or rotates
          the stack, making the new top of the stack the current  working
          directory.   With  no arguments, exchanges the top two directo‐
          ries and returns 0, unless the directory stack is empty.
          .
          .
          dir    Adds  dir  to  the directory stack at the top, making it
                 the new current working directory.

帶有目錄的表單pushd [dir]不使用目前目錄,除非目錄明確用作參數。正在做pushd somedir

答案2

我正在使用zsh,它有一個選項PUSHD_IGNORE_DUPS:「不要將同一目錄的多個副本推送到目錄堆疊上。」。您可能需要檢查您的 shell 選項(因為zsh我需要這樣做unsetopt pushdignoredups。)

相關內容