0x00
什么是CLI?
Command line interface, 即命令行界面,它是在GUI出现之前用于和操作系统进行交互的一种方式。用户通过向被称作shell或command language interpreter的program发送一系列的commands(以successive lines of text的形式)来与操作系统进行交互。
Reference
Command-line interface
is a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines). A program which handles the interface is called a command language interpreter or shell (computing). [From Wiki]
什么是shell?
Shell泛指那些为用户提供与操作系统(实际上是与kernel交互)交互界面的程序。通常shell指的是CLI的解析器(command interpreter)—— 解析从terminal emulator接收到的commands并执行对应的指令
通常shell会检查接收到的commands是否为shell内部的指令,如果是则调用具体的实现。
否则检查PATH中的路径是否存在相应的程序,如果存在则调用这个程序并将参数传递给它。
1 | > cat foo.c |
当执行这样一条command时,shell将会首先检查cat是否是其内部实现,但是cat并不是,所以shell继续搜索PATH变量中声明的所有路径直到找到名为cat的程序。
然后程序cat将被shell调用并传入参数foo.c。cat将会调用system calls —— open, write 来执行输出foo.c文件内容的操作。
虽然这里shell实际上并没有调用system call而是调用的程序cat调用了system call,但我们仍将shell称作是通过调用kernel提供的服务(system call)与kernel交互的程序。
大体上,shell可以划分为两类:
- CLI shell 和 GUI shell
- CLI shell: sh, bash, zsh, fish, etc.
- GUI shell: file explorer(in windows), finder (in Mac os), etc.
什么是kernel?
操作系统中用与和硬件打交道的程序集合,属于操作系统中最底层级的部分。在其之上是system call,在上面是shell,最外面是user application。
剩下的找个时间再填