I. If statement format: Supports if/elif/else forms, supports nesting
1. When command execution succeeds (and exit status is 0), execute Command2
2. When the judging condition is the test command, the Command2 is executed when the result is true
if command; then Command1
Else
Command2fiif commandthen commandfi
Two. For statement format
for var inch List Do Commanddone
1. Read the list of values
A. The values in the list are separated by a space by default,
B. Include single quotes in the value to escape or use double quotation marks
C. The value contains spaces, which need to be enclosed in double quotation marks.
for var inch I\'m come from Nanjing and I want go to "New York", I can\ ' t say Francedo echo $
var
Done
2. Reading a list from a variable
list="AAA BBB CCC"list= $list" CCC" #字符串追加内容 for var inch List Do echo $var Done
3. Read the command value
for var in ' cat/etc/passwd 'does echo $var Done
4. Field Separators
In the 3 example, the content is not output on a row, because space/tab/line breaks are considered field separators in the shell
In the example above, if you want content to be output by row, you need to modify the field delimiter
Ifs. old=$IFSIFS=$'\ n'forvar in ' cat/etc/passwd ' do echo $vardoneifs= $IFS. Old
Three. While statement
Four. Do...until statements
Five. Continue and break statements
Linux Shell 03 Process Control statements