在Linux上,我们都使用过一些linux命令吧,但是,你知道Linux命令到底是什么,它分为哪几类吗?
Linux中命令是如下4中类型中的一种。
1.在$PATH中可执行程序;
2.shell自身的内部命令,即shell builtin;
3.一个shell函数(可以将脚本source而得到其中函数);
4.一个别名(其他命令的别名,用alias命令来定义)。
What Exactly Are Commands?
A command can be one of four different things:
1. An executable program like all those files we saw in /usr/bin. Within this category, programs can be compiled binaries such as programs written in C and C++, or programs written in scripting languages such as the shell, perl, python, ruby, etc.
2. A command built into the shell itself. Bash supports a number of commands internally called shell builtins. The cd command, for example, is a shell builtin.
3. A shell function. These are miniature shell scripts incorporated into the environment. We will cover configuring the environment and writing shell functions in later chapters, but for now, just be aware that they exist.
4. An alias. Commands that we can define by ourselves, be built from other commands.
可以使用type命令来查看一个命令的类型。
下面是一些例子吧:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@kvm-build ~]# type find find is /bin/find [root@kvm-build ~]# type pwd pwd is a shell builtin [root@kvm-build ~]# type ll ll is aliased to ‘ls -l --color=auto‘ [root@kvm-build ~]# type my_function my_function is a function my_function () { echo "hello, my function." } [root@kvm-build ~]# type if if is a shell keyword |
执行命令前,shell按照以下顺序判定程序类型:
1、别名
2、关键字。
3、函数(bash)
4、内置命令
5、可执行程序