首页 > 解决方案 > `cd =-` 是什么意思?

问题描述

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

[csh]$ cd -

并输入

[csh]% cd =-

令人惊讶的是,这奏效了!

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

标签: cshtcsh

解决方案


我认为它与目录堆栈有关,通常由pushdand操作popd

在 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.

推荐阅读