1.什麼是build in指令:
shell内建指令是指bash(或其它版本)工具集中的指令。一般都會有一個與之同名的系統指令,比如bash中的echo指令與/bin/echo是兩個不同的指令,盡管他們行為大體相仿。當在bash中鍵入一個指令時系統會先看他是否是一個内建指令,如果不是才會檢視是否是系統指令或第三方工具。是以在bash中鍵入echo指令實際上執行bash工具集中的bash指令也就是内建指令,而不是/bin/echo這個系統指令。
2.内建指令與系統指令
内建指令要比系統論指令有比較高的執行效率。外部指令執行時往往需要fork出(産生出)一個子程序,而内建指令一般不用。下面(或許以後還會有)這一篇文章将介簡bash的内建指令。
3.檢視一個指令是系統指令還是内建指令:type
[email protected]:~/Documents
$ type -a pwd
pwd is a shell builtin
pwd is /bin/pwd
[email protected]:~/Documents
$ type -a echo
echo is a shell builtin
echo is /bin/echo
可以看出,有些指令,echo和pwd同時是内建指令和系統指令。
4.常見指令的類型
[[email protected] ~]# type -a cd
cd is a shell builtin
[[email protected] ~]# type -a pwd
pwd is a shell builtin
pwd is /bin/pwd
[[email protected] ~]# type -a time
time is a shell keyword
time is /usr/bin/time
[[email protected] ~]# type -a date
date is /bin/date
[[email protected] ~]# type -a which
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
which is /usr/bin/which
[[email protected] ~]# type -a whereis
whereis is /usr/bin/whereis
[[email protected] ~]# type -a whatis
whatis is /usr/bin/whatis
[[email protected] ~]# type -a function
function is a shell keyword
[[email protected] ~]# type -a ls
ls is aliased to `ls --color=tty'
ls is /bin/ls
[[email protected] ~]# type -a ll
ll is aliased to `ls -l --color=tty'
[[email protected] ~]# type -a echo
echo is a shell builtin
echo is /bin/echo
[[email protected] ~]# type -a bulitin
-bash: type: bulitin: not found
[[email protected] ~]# type -a builtin
builtin is a shell builtin
[[email protected] ~]# type -a keyword
-bash: type: keyword: not found
[[email protected] ~]# type -a command
command is a shell builtin
[[email protected] ~]# type -a alias
alias is a shell builtin
[[email protected] ~]# type -a grep
grep is /bin/grep
[[email protected] ~]#