First, understand shell scripting language
Shell script is a program written in C language. When a shell program is executed, the logic code of C language will be executed at the bottom. The shell is a command-line language as well as a programming language.
1.1 the header file
#! bin/bash xx
The first line of the file needs to be marked #! Bin/bash, it means said the file as the shell program, using the bin/bash as interpreter, unity can also use other interpreters, such as: / usr/bin/CSH, and so on
Second, write the grammar
2.1 Declaring Variables
value="xxxx"
Declare variable assignment without Spaces around the “=” sign
2.2 Using Variables
${value} uses a variable like this, marking the boundary of the variable with {}
2.3 use the for
Use for loop, generally for x in range; do xx done;
for item in `ls` for item in 'letter' array=(dfa dfas dasf) for item in ${array} for((i=0; i<10; i++))
3. Replace commands
The use of $() and ‘ ‘can both replace commands and also execute commands and assign values to corresponding variables.
for item in `ls`; do echo item; done
Where $() and ‘ ‘have the same function
4. Parameter manipulation
When you execute the sh file, you can pass parameters such as sh sh.sh param1
5. Follow orders
Commands can be executed in the shell in the following way
lsCommond="ls"
${lsCommond}
It can be executed using (ls).
6. The eval command
When we preface a command line with an eval, the shell scans it twice before executing the command. The eval command will first scan the command line for all substitutions, and then execute the command. This command works for variables that cannot be used in a single scan. This command performs two scans of the variable.
lsc="ls"
lsCommond="${lsc}"
eval ${lsCommond}
If there is no eval, there will be no reaction because ${LSC} will not be resolved to ls