Shell must know and know series | 1. Shell parser

  table of Contents

1. What is a parser?

2. What parsers are there in Linux?

2.1 /bin/bash 和 /usr/bin/bash

2.2 /bin/sh 和 /usr/bin/sh

2.3 /bin/tcsh

2.4 /bin/csh

 Three, summary


To learn Shell, you first need to know the purpose of Shell. This article will introduce you to the Shell parser. 

1. What is a parser?

Shell is a command line parser under the Linux operating system and a tool for users to interact with the Linux kernel. In fact, Shell plays a role similar to a translator, as shown in the following figure (handmade):

Figure 1 Hierarchical structure diagram of Linux operating system

As you can see from the figure above, there is a reason why the parser is named Shell. The entire operating system is actually wrapped layer by layer, which is a layer of abstraction. The higher the degree of abstraction, the easier it is for users to operate. Just like a programming language, the assembler is closer to the bottom, and the C language is more abstract than the assembly language, and the Java language is more abstract.

So, who invented the first Unix Shell?

Ken Thompson developed the Shell when he wrote the first version of UNIX, emulating the implementation of the Shell on Multics.

2. What parsers are there in Linux?

There are several types of Linux parsers:

[root@localhost ~]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/bin/tcsh
/bin/csh
[root@localhost ~]#

/Bin/bash is used by default in CentOS 7, as shown below:

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@localhost ~]# echo $SHELL
/bin/bash
[root@localhost ~]#

2.1 /bin/bash 和 /usr/bin/bash

Bash, a type of Unix shell, was written by Brian Fox for the GNU project in 1987. The first official version was released in 1989. It was originally planned to be used on the GNU operating system, but it can run on most Unix-like operating systems, including Linux and Mac OS X v10.4 to macOS Mojave. As the default shell, since macOS Catalina, the default shell is replaced by zsh. ------ Wikipedia

2.2 /bin/sh 和 /usr/bin/sh

As shown below, /bin/sh and /usr/bin/sh are a soft link of bash.

[root@localhost ~]# ls -l /bin/sh
lrwxrwxrwx. 1 root root 4 9月  24 01:40 /bin/sh -> bash
[root@localhost ~]# ls -l /usr/bin/sh
lrwxrwxrwx. 1 root root 4 9月  24 01:40 /usr/bin/sh -> bash
[root@localhost ~]#

2.3 /bin/tcsh

tcsh is a Unix shell backward compatible with c shell. It essentially adds command completion, command editing and other functions to the c shell. It is currently the default shell for FreeBSD and its extended distributions. ------ Wikipedia

2.4 /bin/csh

C shell is a kind of Unix shell, developed by Bill Joy on BSD system. C shell was born out of /bin/sh in the sixth edition of Unix, and is also the predecessor of Bourne shell. The syntax of this shell is similar to the C language. Compared with the Bourne shell, the C shell has many special features, such as aliases and command history. At present, the C shell is no longer widely used, and its successors include Tenex C shell (tcsh), Korn shell (ksh), and GNU Bourne-Again shell (bash). ------ Wikipedia

 Three, summary

Shell is a bridge between users and the Linux kernel. Shell is also a scripting programming language. Click Follow and will continue to update more Shell must know must know knowledge points~

 

Guess you like

Origin blog.csdn.net/u011074149/article/details/112549892