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

版权声明:本文为博主原创文章,转载请附上博文链接!

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 官网 中文版本 好的网站 Content-type: text/htmlBASH Section: User ...
    不排版阅读 10,034评论 0 5
  • 为何叫做 shell ? shell prompt(PS1) 与 Carriage Return(CR) 的关系?...
    Zero___阅读 8,439评论 3 49
  • bash:Bourne Again shell,是 Linux 上的标配 shell;对于想学习 shell 的人...
    michael_jia阅读 5,312评论 0 4
  • 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个...
    _小老虎_阅读 11,329评论 0 10
  • 《红颜旧》是大名鼎鼎的电视剧琅琊榜中的插曲。初看,歌名加之哀怨婉转的起调“西风夜渡寒山雨”略有“十里平湖霜满天,寸...
    土土动人阅读 5,081评论 2 1

友情链接更多精彩内容