shell命令分類

linux的shell命令總共分為5中,alias,function,file,builtin,keyword。

alias就是別名,function就是自己創建的shell函數,file就是path路徑里的一些二進制或者其他sh文件等掛在硬盤上的文件,keyword就是shell的關鍵字。

可以通過type -t command來查看,另外如果一個命令是file的話,可以通過type -p command查看該命令的絕對路徑..。

關于一個命令的運行到底有沒有開辟新的進程,我們可以通過一種方法查看,首先運行該命令,然后ps -elf | grep一下就可以了,可以肯定的是file類型的command肯定是在子進程中運行的,但是builtin就不好說了,我man type一下:


Shell builtin commands are commands that can be executed within the running shell's process.? Note that, in the case of csh(1) builtin commands, the command is executed in a sub-

?? ? shell if it occurs as any component of a pipeline except the last.


?? ? If a command specified to the shell contains a slash ``/'', the shell will not execute a builtin command, even if the last component of the specified command matches the name of

?? ? a builtin command.? Thus, while specifying ``echo'' causes a builtin command to be executed under shells that support the echo builtin command, specifying ``/bin/echo'' or

?? ? ``./echo'' does not.

上面說的很清楚,第一段的意思是builtin命令可以在當前shell中運行,但是在csh中,如果在使用管道的時候內建命令不是在最后面,就會在子進程中運行。第二段的意思是如果使用絕對路徑或者相對路徑使用命令,即使最終引用的命令和builtin命令一樣,也會在子進程中運行,相當于file類型的了。

阿里云雙十一云服務器拼團活動,已經打到最低價99元一年!有需要的可以考慮一波了!

https://m.aliyun.com/act/team1111/#/share?params=N.9g4CZ2TwSh.qilw7y0a

---------------------

作者:pysta

來源:CSDN

原文:https://blog.csdn.net/Yvlen/article/details/79254439

版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 官網 中文版本 好的網站 Content-type: text/htmlBASH Section: User ...
    不排版閱讀 4,434評論 0 5
  • 為何叫做 shell ? shell prompt(PS1) 與 Carriage Return(CR) 的關系?...
    Zero___閱讀 3,182評論 3 49
  • bash:Bourne Again shell,是 Linux 上的標配 shell;對于想學習 shell 的人...
    michael_jia閱讀 1,407評論 0 4
  • 一、Python簡介和環境搭建以及pip的安裝 4課時實驗課主要內容 【Python簡介】: Python 是一個...
    _小老虎_閱讀 5,801評論 0 10
  • 《紅顏舊》是大名鼎鼎的電視劇瑯琊榜中的插曲。初看,歌名加之哀怨婉轉的起調“西風夜渡寒山雨”略有“十里平湖霜滿天,寸...
    土土動人閱讀 1,026評論 2 1