What are the linux shell process control statements?
This article mainly talks about "what are the linux shell process control statements". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the linux shell process control statements?"
I. shell conditional statement (if usage)
If statement structure [if/then/elif/else/fi]
The code is as follows:
If conditional test statement
Then
Action
[elif condition
Action
Else
Action
]
Fi
If the conditional test statement is not very clear, you can refer to: linux shell logical operator, logical expression detailed explanation
The shell command, which can be divided by semicolon or newline character. If you want to write more than one command per line, you can split it with ";".
Such as:
The code is as follows:
[chengmo@centos5] $axi5bot if [[a-gt 4]]; then echo 'ok';fi
Ok
Example: (test.sh)
The code is as follows:
#! / bin/sh
Scores=40
If [$scores-gt 90]; then
Echo "very good!"
Elif [$scores-gt 80]; then
Echo "good!"
Elif [$scores-gt 60]; then
Echo "pass!"
Else
Echo "no pass!"
Fi
Conditional tests include: [[]], [], test. Note: [[]] is separated from variables by spaces.
2. Circular statement (for,while,until usage):
1.for recycling method (for/do/done)
Grammatical structure:
The code is as follows:
1.for... In statement
For variable in seq string
Do
Action
Done
Description: as long as the seq string is separated by space characters, each time for. When in reads, the values are read sequentially to the preceding variables.
Instance (testfor.sh):
The code is as follows:
#! / bin/sh
For i in $(seq 10); do
Echo $I
Done
Seq 10 produces 1 2 3. 10 spaces separate strings.
2.for ((assignment; condition; Operation statement))
The code is as follows:
For ((assignment; condition; Operation statement))
Do
Action
Done
Instance (testfor2.sh):
The code is as follows:
#! / bin/sh
For ((iTun1)