`cd =-` 是什么意思?

What is the meaning of `cd =-`?

像往常一样,我输错了命令

[csh]$ cd -

并输入

[csh]% cd =-

令人惊讶的是,这有效!

Question: What does the meaning of the equal-sign (=) here?

我觉得是跟目录栈有关,一般是pushdpopd操作的。

在csh中,cd =(index)从目录栈中取出那个索引的元素,并替换栈顶元素(索引0),也是当前目录

- 因为这里的索引是目录堆栈中的底部元素。或者,如果目录堆栈仅包含当前目录,则 - 用于上一个目录,这意味着您 popd 出所有目录或者您根本没有使用 pushd。在这种情况下,cd =-cd -.

的工作方式相同

这是手册页的解释:

   Directory stack substitution (+)
   The  directory stack is a list of directories, numbered from zero, used by the pushd, popd and dirs builtin commands (q.v.).  dirs can
   print, store in a file, restore and clear the directory stack at any time, and the savedirs and dirsfile shell variables can be set to
   store  the  directory  stack  automatically on logout and restore it on login.  The dirstack shell variable can be examined to see the
   directory stack and set to put arbitrary directories into the directory stack.

   The character ‘=’ followed by one or more digits expands to an entry in the directory stack.  The special case  ‘=-’  expands  to  the
   last directory in the stack.  For example,

       > dirs -v
       0       /usr/bin
       1       /usr/spool/uucp
       2       /usr/accts/sys
       > echo =1
       /usr/spool/uucp
       > echo =0/calendar
       /usr/bin/calendar
       > echo =-
       /usr/accts/sys

   The  noglob  and  nonomatch  shell variables and the expand-glob editor command apply to directory stack as well as filename substitu-
   tions.