A-1 talked about some basic grammar, continue to the last part of the contents of A2 and then speak.
A shell is a programming language, but also as a representation of the structure. Common programming language is structured judgment and cycling. Analyzing the shell into three categories: judgment value, character determination, the file is determined.
Analyzing several forms of
the If Command
the Then
Command
Fi
If command
Then
command
Else
command
Fi
If command
Then
command
Elif command
Then
command
Else
command
fi
(1) digital judgment
Example: The simple number guessing
(2) determine the character
Example: option determines whether the input
(3) to determine the file
Example: Create a log file before checking the target path exists
# / bin / bash!
IF [-d /! mnt / 123testlog / 2019-08-31]
the then
mkdir -p / mnt / 123testlog / 2019-09-31
Fi
Also need to focus
If test xxxx usage
parameters worth judgment processing
complex conditions to determine
the If [] && []
the If [] || []
Double parentheses
- double parentheses (mathematical expressions advanced features)
- double square brackets (String advanced features)
When using multiple selection deciding if the structure is more complicated, and more preferably using case
Case
Case xxx in
p1)
cmd
;;
p2)
cmd
;;
*)
default cmd
;;
Esac
When the script processing the input parameters may be used Case, then the parameters shift processing
process can also be used as an input, and later use getopt getopts re specific description.
Getopt
the Getopts
the Read