2019年2月11日 / 77次阅读
Shell
我们在shell界面下输入的命令,有些是内部命令,有些是外部命令。
shell在接受到一个命令后,如果是内部命令(built-in),直接就像调用函数一样执行,如果是外部命令,则fork后exec执行这个外部命令。
通过type命令,可以判断哪些是内部命令,哪些是外部命令:
[xinlin@localhost ~]$ type cd
cd is a shell builtin
[xinlin@localhost ~]$ type pwd
pwd is a shell builtin
[xinlin@localhost ~]$ type type
type is a shell builtin
[xinlin@localhost ~]$ type echo
echo is a shell builtin
[xinlin@localhost ~]$
[xinlin@localhost ~]$ type ls
ls is aliased to `ls --color=auto'
[xinlin@localhost ~]$ type ll
ll is aliased to `ls -l --color=auto'
[xinlin@localhost ~]$ type which
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[xinlin@localhost ~]$ type cat
cat is /usr/bin/cat
[xinlin@localhost ~]$ type more
more is /usr/bin/more
[xinlin@localhost ~]$ type less
less is /usr/bin/less
外部命令本质上就是一个独立的程序,被shell调用而已,一般情况,shell要等待程序执行结束返回后,才能继续接受我们的下一条命令。当然,也可以是batch模式,直接运行一个shell脚本文件。
本文链接:https://www.maixj.net/ict/neibu-waibu-20083
《Shell的内部命令与外部命令》有1条留言
©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。
当你在 shell 中执行“外部命令”,shell 会启动对应的可执行文件,从而创建出一个“子进程”;而如果是“内部命令”,就【不】产生子进程。 [ ]