The article is for personal opinion, please correct me.
Before we introduce the shell script, let's begin by understanding some basic concepts. What is a program? Process? The program is a set of instructions plus data, the following diagram can clearly see the concept of the program
The program itself is static and can only become dynamic when it is executed by the CPU. However, the CPU execution speed is very fast, one execution of a program, will greatly waste the efficiency of the CPU, so it is derived from the concept of multi-channel program. Multi-Channel program processing, is the same time interval of multi-channel program execution concurrently, but the program itself between the execution of data error prone to occur. Processes are used to coordinate these programs from one to the other, so the process is dynamic. When the program is going to run, when the memory is transferred to the program, the resources are allocated to the programs, and then the process control blocks are assigned to record the information, when the program is completed, the process control blocks are recycled and the resources are recycled. Such as:
The process is dynamic.
Here is the concept of programming language: The programming language is divided into high-level and low-level language, the language is not to say that the higher the better, low-level means that the closer to the bottom, the higher the higher the closer the human natural language, lower-level language execution efficiency will be relatively high. Such as
As we can see, the shell language is also a high-level language, the shell language is an explanatory language, and the shell is an interpreter (like bash). Explanatory language is like a simultaneous translation, an execution of a sentence, a translation. Compiled language, is a full translation, put it there, who can go to run. So generally speaking, the compilation line language execution is very efficient, but the prophase will take time to compile, can only speak two types of language, each has advantages. Here's a primer on Shell basics
First, we'll see the beginning of the first face in all the scripting languages.
This begins with what we call the shebang mechanism, and his main function is to tell the system that the file should be executed by the Bash interpreter, followed by the body of the program.
The content of the text is what you want to complete, then how to write the text content? The main ideas are as follows:
- Demand analysis
- Program Logic Analysis
- Writing Program
- Debugging bugs
First, let's take a simple script topic as an example:
The main code of the program is as follows:
Let's analyze:
The main function of this problem is to create the user and change the password. But before we create the user, we need to meet some conditions that we can use as a judgment statement, and when these conditions are met, we go to the next step, and when all the conditions are met, we can do what we want to accomplish.
Through, we can clearly know when the script needs, how to think, where to start, we will not be able to begin.
Getting Started with Shell scripting basics