Usando a opção -n com pushd e popd

1
  1. popd

    Remove the top entry from the directory stack, and cd to the new top directory. When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; that is, popd is equivalent to popd +0.

    -n
    Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated.

    /home/t$ dirs -v
     0  ~
     1  /tmp
     2  ~/mydata
    /home/t$ popd -n
    ~ ~/mydata
    /home/t$ dirs -v
     0  ~
     1  ~/mydata
    

    Por que não:

    /home/t$ dirs -v
     0  /tmp
     1  ~/mydata
    
  2. pushd

    Options:

     -n     Suppresses the normal change of directory when adding
            directories to the stack, so only the stack is manipulated.
    

    Arguments:

     +N     Rotates the stack so that the Nth directory (counting
            from the left of the list shown by 'dirs', starting with
            zero) is at the top.
    
     -N     Rotates the stack so that the Nth directory (counting
            from the right of the list shown by 'dirs', starting with
            zero) is at the top.
    

     dir    Adds DIR to the directory stack at the top, making it the
            new current working directory.
    
    /tmp$ dirs -v
     0  /tmp
     1  ~
     2  ~/mydata
    /tmp$ pushd -n +1
    /tmp$ dirs -v
     0  /tmp
     1  ~/mydata
     2  /tmp
    

    por que não:

    /tmp$ dirs -v
     0  ~
     1  ~/mydata
     2  /tmp
    

    ou

    %código%
por Tim 07.02.2016 / 08:50

1 resposta

0

É bem óbvio o que o -n faz: ele não altera a pilha no índice 0.

O índice 0 é sempre o $PWD (ou pwd ) e é não alterado se a opção -n for usada.

Ou seja: popd ou pushd não executará cd .

Para outras questões, faça uma nova pergunta.

    
por 10.02.2016 / 05:01

Tags