linux shell basic grammar A-2

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
linux shell basic grammar A-2
Example: The simple number guessing
linux shell basic grammar A-2
(2) determine the character
linux shell basic grammar A-2
Example: option determines whether the input
linux shell basic grammar A-2
(3) to determine the file
linux shell basic grammar A-2
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)
linux shell basic grammar A-2
- double square brackets (String advanced features)
linux shell basic grammar A-2

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

Guess you like

Origin blog.51cto.com/12374206/2434424