Today we learned the Bash feature multi-command execution includes a logical relationship between the various commands. It contains the execution of the "and" or "not" commands. The following is the relationship between these logical command relationships that we have learned.
Select the execution structure:
Logical operation:
With: Logical multiplication,&&
0: Successful execution of-->true
1-255: Failure-->false
True && true =true
True && false = False
False && true = False
False && false = False
The short-circuit logic operation of the "and" Operation: As long as the first operand is false, the result of its logical operation must be false;
COMMAND1 && COMMAND2
If the COMMAND1 can be executed successfully, the COMMAND2 will be executed;
If the COMMAND1 execution fails, the COMMAND2 is not executed.
Or: logical addition, | |
true | | True = True
true | | False = True
False | | True = True
False | | False = False
"or" short-circuit logic operation: As long as the first operand is true, the result of its logical operation must be true;
COMMAND1 | | COMMAND2
As long as COMMAND1 can execute successfully, COMMAND2 is not necessary to execute.
The COMMAND2 will only be executed if the COMMAND1 execution fails.
Non: logical inversion,! , single-Mesh operator
! STRING: Reads the contents of the command history space;
! true = False
! False = True
! COMMAND
! COMMAND1 && COMMAND2 equivalent to COMMAND1 | | COMMAND2
! COMMAND1 | | COMMAND2 equivalent to COMMAND1 && COMMAND2
Demogan Law:
! (A && B) ==! A | | ! B
! (A | | B) ==! A &&! B
Logical operation Symbol Priority:! >&& >| |
XOR (Binocular operation): is different than the two operands, if different, the result of the logical operation is true, if the same, the result of the logical operation is false;
Shell script Programming:
What do you mean by programming? In simple terms, 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 into a file, so that the computer sequential reading, so as to achieve the function;
Programming Languages:
Advanced Language:
Depending on how the source code is handled:
Compiled run language: source code--compiler (compile)---Assembler (assembly)-->[Linker (link to library)]--> binary files that can be executed directly;
Explain the running language: source code--and directly start the interpreter program corresponding to the source code, interpreted by the interpreter side execution;
Depending on the implementation of the functionality in the programming process, the call library or the external programming language is called;
Complete programming Language:
Programming with libraries or programming components:
Script programming Language:
Interpreter
Shell script: Call the shell program, second call the required external command file; command interpreter
It provides a single programming function interface, and supports the process programming logic.
According to the programming paradigm: Program = instruction + data
Programming Languages:
With instruction as the center, the design data and data structure are designed around the instruction (algorithm).
The implementation form of an algorithm or instruction:
Sequential execution selection Execution 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 programs to determine whether a command satisfies its operating conditions to avoid serious errors during operation.
The code content in the shell script:
1. The first line must be shebang, (shelf write) to explain its path, must occupy an absolute beginning, at the time of execution, start the corresponding interpreter to explain the script in the many commands;
#! /bin/bash
#! /bin/sh
#! /usr/bin/python
#! /usr/bin/perl
2. In the shell script, in addition to Shebang, the # occupies the absolute beginning of the content, is the comment line, the interpreter ignores the contents of such a line;
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 runs in the current shell according to Shebang's instructions, an interpreter (child shell) is opened explaining the execution of the code, 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, emace, Pico
Recommended use of VIM
Convention, the suffix of the script file name is. SH can also be added without
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 is executed, the script name is not given a path, and 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;
Bash/path/to/script_file
Linux Learning notes: Bash features multi-command execution, shell scripting