Which
為什麼我不能哪個 pushd
pushd
在編寫 bash 腳本時,我已經使用popd
了很長時間。但是今天當我執行時which pushd
,我沒有得到任何輸出。我完全無法理解這一點。我一直認為這pushd
只是一個命令,就像cd
,ls
等等。那為什麼
which pushd
什麼都不給我?
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://structure.usc.edu/bash/bashref_4.html中找到。
您還可以使用
compgen -b
或enable
獲取所有這些內置函式的完整列表:補償
$ 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