When I started using macOS from Linux conversion, I found that the terminal of macOS was ugly. It looked like this:

So I found this article: Mac OS terminal iTerm2 and zsh configuration

So what is terminal , what is zsh

terminal

A long time ago, the concept of terminal was as follows:

It is a kind of hardware Input/output device , for and computers Exchange of information

Operation of terminal : User via terminal input command , the terminal transmits the command to the computer, executes it, and inputs the result to terminal Is displayed on the.

It is not difficult to see from this concept Teletype printer Conform to this concept:

But now the degree of computer hardware integration is getting higher and higher, and the quality of hardware is also getting stronger and stronger, It is unnecessary for I/O equipment to exchange information with a computer using a hardware alone. Instead, it uses a software terminal to exchange information with the computer.

This is it. Terminal Emulator , which is what we are talking about now terminal Except that it is not hardware, it conforms to the concept and workflow of terminal.

For example, the following software is terminal one

GNU/Linux:gnome-terminal、Konsole;
macOS:Terminal.app、iTerm2;
Windows: Win32 console, ConEmu, etc.

shell

I was puzzled by the question that a terminal is enough. Enter commands, execute and output the results. What do you want the shell to do. There are also many types of shell that make people more crazy, bash, cshell, zsh. What on earth do these do

So it needs to be clear Work undertaken by the terminal

Operating range of terminal : Receive the user's input and display the transmitted output. In addition, it also provides some functions to optimize the user experience , such as supporting copy and paste of text, adjustment of software background color, etc.)

In fact, the work of the terminal is very few. To put it simply, there are three points: GUI software interface, receiving input, and displaying output.

The core work of the shell is Manipulate the computer kernel (such as creating new files, etc.) , i.e Accessing a file (binary file -- this kind of file is often called a tool) that has certain functions and can handle specific transactions in the operating system, or a file containing certain content (text file) two

The shell is divided into:

  • Graphical shell( Graphical desktop environment ), such as Windows Explorer (File Manager) and Linux desktop environments: KDE, GNOME, CDE, XFCE, etc.
  • Command line shell. E.g. bash, sh, csh, ksh

We generally refer to the command line shell when we talk about the shell.

Why is the shell called the command interpreter

Both GUI shell and command line shell are actually interpreting commands, but GUI shell hides the details of interpreting commands, and users can operate kernel commands by clicking the mouse.

Why is a shell called a shell

As shown in the figure above, the shell calls system calls and related API operation kernel commands through parsing commands, and then reads and writes hardware to complete tasks. The shell is the outermost layer of receiving user operations, which is wrapped in the whole calling process like a shell.

Why are there so many command line shells

Shell and shell scripting language Not exactly the same concept. In addition to the command syntax specification (shell language) and command parsing, the shell also includes some additional functions (such as command completion, topics, etc.)

The shell language is not very different from any other advanced languages we learn, such as c, python, and java. different Shell language It can be seen as different versions of the Java language.

There are two main differences between different shells:

  • There are differences in script language syntax
  • There are differences in function, appearance, customization and beautification

scripting language

Early sh did not even support the syntax to set aliases for long commands. three

Although zsh is fully compatible with bash syntax, there are some syntax differences. See What's the difference between ZSH and Bash? The pit is deep

Custom function configuration

Unless we need to write shell scripts, it is difficult for ordinary users to find differences in different shell script languages.

Operation on file ls pwd These common commands are supported by all shells.

So our ordinary users pay more attention to the differences in details, appearance and functions. Zsh does this exceptionally well.

Such as color highlighting, command prompt, intelligent completion, fast jump and other additional functions. four

When we talk about configuring terminals, we are actually talking about configuring shells.

Why is zsh so popular?

This newer shell is compatible with bash, but includes more features. The zsh shell provides built-in spelling correction, improved command line completion, and serves as a loadable module for shell plug-ins, allowing you to alias file names or global aliases of anything else on the command line, not just commands, but also more topic support. It is like bash, but there are many additional functions, additional functions and configurable options. You may like it if you spend a lot of time on the command line. three

Summary: Terminal is software, the outermost layer, shell=shell scripting language parser+editing, appearance and other additional functions

Switching between different shells

input cat /etc/shells , you can view all shells on the local machine:

Temporary switching

For example, switch bash and input directly bash , switch to bash environment, enter exit , restore the default shell environment.

Default switch five

 #Use the zsh provided by the system: enter the password to successfully switch, and restart the terminal to use zsh. chsh -s /bin/zsh #Use third-party zsh, such as zsh installed from brew. sudo chsh -s /usr/local/bin/zsh
Last modification: May 17, 2021
Do you like my article?
Don't forget to praise or appreciate, let me know that you accompany me on the way of creation.