为什么我不能推送

为什么我不能推送

我在编写 bash 脚本时已经使用pushdandpopd很长时间了。但是今天当我执行时which pushd,我没有得到任何输出。我根本无法理解这一点。我一直认为这pushd只是一个命令,就像cd等等ls

那么为什么什么which pushd也没有给我呢?

答案1

popd它们pushd是 Bash 中内置的命令,它们并不是作为真正的二进制文件存在于 HDD 上的实际可执行文件。

bash 手册页摘录
   DIRSTACK
          An array variable (see Arrays below) containing the current 
          contents of the directory stack.  Directories appear in the stack 
          in the order they are displayed by the dirs builtin.  Assigning to 
          members of  this  array variable may be used to modify directories 
          already in the stack, but the pushd and popd builtins must be used 
          to add and remove directories.  Assignment to this variable will 
          not change the current directory.  If DIRSTACK is unset, it loses 
          its special properties, even if it is subsequently reset.

所有内置命令的完整列表可以在 Bash 手册页以及此处找到 -http://struct.usc.edu/bash/bashref_4.html

您还可以使用compgen -benable来获取所有这些内置函数的完整列表:

康普根
$ compgen -b | grep -E "^push|^pop"
popd
pushd
使能够
$ enable -a | grep -E "\bpop|\bpus"
enable popd
enable pushd

此外,如果您想获得有关内置命令的帮助,您可以使用以下help命令:

$ help popd | head -5
popd: popd [-n] [+N | -N]
    Remove directories from stack.

    Removes entries from the directory stack.  With no arguments, removes
    the top directory from the stack, and changes to the new top directory.

$ help pushd | head -5
pushd: pushd [-n] [+N | -N | dir]
    Add directories to stack.

    Adds a directory to the top of the directory stack, or rotates
    the stack, making the new top of the stack the current working

相关内容