Bash's script preliminary
Shell script: Another form of preserving historical commands;
Shell script Programming:
What do you mean by programming?
Write the program source code.
In order to enable users to use the computer, you can let the computer do some tasks in a non-interactive way, you need to make these tasks called a file, so that the computer read sequentially, so as to achieve the function;
Programming Languages:
Advanced Language:
Depending on how the source code is handled:
Compile run language:
Source---compiler (compile)---Assembler (assembler)--the linker (library link)--binary files that can be executed directly;
Explain the running language:
Source code---Directly starts the interpreter program corresponding to the source code, which is executed by the interpreter side.
Depending on the implementation of the functionality in its programming process, the call library or the external program file is called:
Full programming language:
Programming with libraries or programming component processes;
Scripting language:
Interpreter
Shell script: Call the shell program, second call the required external command file; command interpreter
The shell provides a single-function programming interface: Support for process-programmed logic;
According to the program's writing mode: program = instruction + data
Programming Languages:
Command-centric, around the implementation of the instruction (algorithm) design data and structure, data for the instruction server;
The form of implementation of a calculation or instruction:
Sequential execution
Select Execute
Loop execution
Object-Type programming language:
Data-centric, instantiating data into classes, and deploying directives around the needs of data
Classes, properties, methods
Low-level language:
Assembly:
Shell script Programming
An over-programming language that interprets runs, relies on external program files to run;
What exactly is a shell script?
1. Plain text Document--the data stored in the file is stored in characters;
2. The combination of a large number of commands to solve user problems according to the user's needs;
3. "Power of Execution"-the result of multiple executions of any command is consistent;
Many commands do not have "idempotent", and in shell scripts it is necessary to use a large number of program logic to determine whether a command satisfies its operating conditions to avoid serious errors during operation;
Code content in a shell script
1. The first line must be shebang, the interpreter path, must occupy the absolute beginning, when executing, launches the corresponding interpreter to explain the script many commands;
#!/bing/bash
#!/bing/sh
#!/usr/bin/python
#!/usr/bin/per1
2. In the shell script, except for Shebang, the contents of the absolute beginning of the line with # are the comment lines, and the interpreter ignores the contents of such lines;
3. The explanation ignores all blank lines in the script;
4. Lots of commands and keywords (if,else,then,do,while,for,... )
Note: Once the shell script is running, it is in the current shell to open an interpreter (child shell) to interpret the execution code as instructed by Shebang, and the contents of the shell script are implemented in a child shell process;
We can use text editing tools to write shell scripts;
Nano, VI, Vim, Emacs, Pico
Recommended use of VIM
Under the Convention, the script file name suffix is. SH, also can not add;
How the script works:
1. Assign execute permissions to the script file and run the file directly;
chmod +x/path/to/script_file
~]#/path/to/script_file
If the script file name does not give the path when the script is executed, you must ensure that the script is found in the path that is saved in the paths variable;
2. Run the script directly using the interpreter and use the script as the parameter of the interpreter command;
#6 Shell Scripting Insights and programming