cd =-是什么意思?

时间:2019-11-07 06:18:25

标签: csh tcsh

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

[csh]$ cd -

然后键入

[csh]% cd =-

令人惊讶的是,这行得通!

  

问题:这里的等号(=)是什么意思?

1 个答案:

答案 0 :(得分:1)

我认为它与目录堆栈有关,通常由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.