什麼是Bash Shell的內建(build in)命令

來源:互聯網
上載者:User

1.什麼是build in命令:

shell內建命令是指bash(或其它版本)工具集中的命令。一般都會有一個與之同名的系統命令,比如bash中的echo命令與/bin/echo是兩個不同的命令,儘管他們行為大體相仿。當在bash中鍵入一個命令時系統會先看他是否是一個內建命令,如果不是才會查看是否是系統命令或第三方工具。所以在bash中鍵入echo命令實際上執行bash工具集中的bash命令也就是內建命令,而不是/bin/echo這個系統命令。
 

2.內建命令與系統命令
 
內建命令要比系統論命令有比較高的執行效率。外部命令執行時往往需要fork出(產生出)一個子進程,而內建命令一般不用。下面(或許以後還會有)這一篇文章將介簡bash的內建命令。

3.查看一個命令是系統命令還是內建命令:type
 
bkjia@www.bkjia.com:~/Documents
 $ type -a pwd
 pwd is a shell builtin
 pwd is /bin/pwd
 
bkjia@www.bkjia.com:~/Documents
 $ type -a echo
 echo is a shell builtin
 echo is /bin/echo
 

可以看出,有些命令,echo和pwd同時是內建命令和系統命令。

4.常見命令的類型 


[root@bkjia ~]# type -a cd 

cd is a shell builtin
 [root@bkjia ~]# type -a pwd
 pwd is a shell builtin
 pwd is /bin/pwd
 [root@bkjia ~]# type -a time
 time is a shell keyword
 time is /usr/bin/time
 [root@bkjia ~]# type -a date
 date is /bin/date
 [root@bkjia ~]# type -a which
 which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
 which is /usr/bin/which
 [root@bkjia ~]# type -a whereis
 whereis is /usr/bin/whereis
 [root@bkjia ~]# type -a whatis
 whatis is /usr/bin/whatis
 [root@bkjia ~]# type -a function
 function is a shell keyword
 [root@bkjia ~]# type -a ls
 ls is aliased to `ls --color=tty'
 ls is /bin/ls
 [root@bkjia ~]# type -a ll
 ll is aliased to `ls -l --color=tty'
 [root@bkjia ~]# type -a echo
 echo is a shell builtin
 echo is /bin/echo
 [root@bkjia ~]# type -a bulitin
 -bash: type: bulitin: not found
 [root@bkjia ~]# type -a builtin
 builtin is a shell builtin
 [root@bkjia ~]# type -a keyword
 -bash: type: keyword: not found
 [root@bkjia ~]# type -a command
 command is a shell builtin
 [root@bkjia ~]# type -a alias
 alias is a shell builtin
 [root@bkjia ~]# type -a grep
 grep is /bin/grep
 [root@bkjia ~]#

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.