Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities.

This paper has participated inProject DigginTo win the creative gift package and challenge the creative incentive money.

preface

We are not unfamiliar with operating systems (OS). We have entered Windows or MAC operating systems since we started to contact computers

When we study operating systems, we will have a comprehensive understanding of the evolution of operating systems from Unix to Linux to the modern Windows and MAC operating systems

Because Linux is based on the server-side, uses the Linux kernel, command line control operation and open source characteristics, Linux system has been popular in our daily life, such as the Internet of things, smart home appliances, TV, AI speakers and so on are loaded with Linux system

A Linux system generally consists of two parts: user space and kernel space.

In this installment, we will learn about the shell tool that connects user space and kernel space in Linux, passing commands for Linux

Summary of the shell

Shell is the user interface of Linux system, a bridge for the user and the kernel to exchange operations. The shell receives the user’s input and sends it into the kernel to execute.

Shell features:

  • The shell is a command interpreter: it interprets the commands entered by the user and sends them to the kernel for execution
  • The shell is a programming language: it defines variables and parameters and provides control structures such as loops and conditional judgments

Shell Workflow

The shell itself is a C language program. As a command language interpreter, it has its own built-in shell command set.

Other applications in the system can also invoke Shell commands

At the same time, as a part of Linux system, shell can call most functions of Linux system core to execute programs and coordinate the operation of each program

After receiving the command from the user, shell performs the following steps:

  1. Shell checks whether the command is internal
  2. If it is not an internal command, the shell checks for an application in the search path
  3. If the application (executable) is not found, an error message will be displayed
  4. If it detects an internal command or application, the shell splits the internal command or application into system calls and passes them to the Linux kernel

The shell type

On Linux systems, bash is the default shell

Currently, there are five types of popular shells:

  • Ash (Ash shell)

    Ash is the least resource-intensive shell on Linux, with only 24 commands

  • Bash (BournAgain shell)

    BourneAgain Shell is the default shell used in Linux system. It has 40 internal commands and is compatible with Bourn shell and has many features.

    1. Provides the command query function. You can query, enter, and modify commands using arrow keys
    2. Supports the automatic command completion function
    3. Provide the help query at the bottom of the prompt for the operation help of the relevant instructions
  • KSH (Korn Shell)

    Korn Shell has 42 commands and is fully compatible with commercial KSH

  • CSH (C shell)

    CSH is the shell pointing to /bin/tcsh, which is the largest kernel in Linux, with 52 internal commands

  • zch

    ZCH has the most internal commands of any shell, with 84.

Shell the pros and cons

The shell is not only a command interpreter, but also an interpretive programming language, so it can be used in a wide variety of usage scenarios.

Shell advantages:

  • Simple grammar, quick to learn
  • Quick command lookup
  • Interpreted language, no compilation required
  • Script development is efficient and can quickly replace repetitive steps
  • Use AWK, SED to quickly handle text requirements

Shell faults:

  • For complex problems, the implementation is tedious and the expression is not easy to read
  • For variable definition parameters, not intuitive, easy to lead to misleading
  • Since the shell itself is an interface, it needs to spend a lot of system resources to perform tasks

Shell usage scenarios:

  • For complex command steps such as git upload code, integrate one step
  • Replace some necessary steps such as the installation of APK steps, automation scripts
  • Software automatic packaging, compilation, release and other functions
  • Delete disk files and create files

conclusion

This time, we understand and learn about the composition of Linux system, shell workflow and types, and master the features and application scenarios of shell scripts.

Shell script is an interpretative programming language. It can be seen everywhere in our work scenes because of its simple syntax and quick start

That’s the content of this episode, you are welcome to like and comment, see you next time ~