在調試板子的時候,發現在PATH對應的路徑中沒有alias這個命令,但是居然可以用,
查閱資料後,終於明白shell是如何執行命令解釋了。
首先shell判斷使用者輸入的命令是否是內部命令
*是內部命令,直接執行
*不是內部命令,在PATH對應的目錄中搜尋對應的單獨的程式,存在執行,不存在報錯
linux的命令可以分為內部命令和外部命令。
內部命令在系統啟動時就調入記憶體,是常駐記憶體的,所以執行效率高。
而外部命令是系統的軟體功能,使用者需要時才從硬碟中讀入記憶體。
在終端下輸入man builtins,即可調出內部命令的大綱和解釋
[root@localhost bin]# man builtins
BASH_BUILTINS(1) BASH_BUILTINS(1)
NAME
bash, :, ., [, alias, bg, bind, break, builtin, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable,
eval, exec, exit, export, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read,
readonly, return, set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, unalias, unset, wait - bash
built-in commands, see bash(1)
或者使用enable命令,分行列出內部命令
[root@localhost bin]# enable
enable .
enable :
enable [
enable alias
enable bg
enable bind
enable break
enable builtin
enable caller
enable cd
enable command
enable compgen
enable complete
如果想查一下一個命令是內部的還是外部的,可以這樣:
[root@localhost bin]# enable ls
-bash: enable: ls: not a shell builtin