By the previous study, we have a certain understanding for linux file system, we are going to be the initial contact programming principles and try to write shell scripts to function.
day05-- programming principles and shell scripts preliminary understanding
Principles of Programming
In the early programming, as an instruction to make the communication between different manufacturers of hardware devices, often using assembly language programs. And now based on high-level language programming and ultra-high-level language, translated into computer-readable binary instructions, enhanced readability, enable programmers to achieve a better programming
Programming language into interpreted and compiled ,
Interpreted features are: progressive translation, line by line. Such as shell python
Compiled is characterized by: a compilation, all executed. C language such as C ++
shell scripting language introduced
shell script comprising: a command 2, 3 variables, logical relationship
shell defined in the Script Editor #! / bin / bash , which will be written in a code
Use bash command to execute the script
bash - logical errors n # to view the shell script
bash -x # Progressive script execution
Or to grant permission to execute the script chmod + x script name , then use ./ script name can execute scripts
variable
Echo $ PATH environment variable display environment variable
Local variables defined in command variable type decclare
Local local variables used in the function
Parameter passing
$ -? Command execution status of 0 on a 1-255 correct errors
$ 1 $ 2 ... $ {10} - command script incoming data back to a space-delimited
$ # - $ {amount of statistical parameters passed $ #}?
$ * - indicates that all mass participation, mass participation of all output as a string
$ @ - represents all the parameter passing, pass all the parameters output in the form of a list of
[the work to be performed for all transmission parameters when in operation, it is necessary to consider and $ @ $ *]
test test file, conditional
In the script, we need to make the statement branch; it plainly, they do judge
judge is to use the test command to achieve;
using the format:
1, test [the Option] File
2, [conditionals]
common test options:
compare options:
- eq equal
-ne not equal
-gt greater than
-ge greater than or equal
-lt less than
-le less
Analyzing options:
-f determining whether a regular file
-d determines whether the directory file
-L determines whether the connection file
-r -w -x determining whether the file has write execute permissions
associated options:
-o or
-a with
non!
string determination:
= determining whether both sides of the same string
= is not equal to!
the -Z determines whether the string is present
opposite and -n -z, the presence of is false, there is no true
logic operation
And &&: both sides of the commands are true, the result is true
or ||: both sides of the command, while true, is true, but false, is false
non =!
The logical operator command before and after docking is present alone;
[$ 0 -eq?] 0 && Exit Exit. 1 ||