Почему в csh работает cd (знак равенства) (тире)? - PullRequest
0 голосов
/ 07 ноября 2019

(Извините за запутанный заголовок. Не могу поставить =, войдите в это ...)

Я просто собирался cd - как обычно, но опечатался как cd =-. Удивительно, но это также работает!

Я провел больше экспериментов и обнаружил, что cd =- работает только в csh, но не в bash и не в zsh.

Что означает здесь знак = в csh

1 Ответ

0 голосов
/ 07 ноября 2019

Я думаю, что это связано со стеком каталогов, которым обычно манипулируют pushd и 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.
...