How to handle the programming logic:
1, sequential execution
2, select Execute
3, loop execution
Conditional Select if statement
Select Execute:
Note: If statements can be nested
Single Branch
if judgment condition; then
Branch code with true condition
Fi
Example code:
1 #!/bin/bash
2
3 #Author: Wangjun
4 #Version: 1.0
5 #Create time:2016-08-13 19:40:55
6 #Description: Ifsingle test
7
8 Read-p "Please input a username:" Name
9 If ID $name &>/dev/null; then
echo "$name user exists,user ID: ' Id-u $name '"
One fi
650) this.width=650; "title=" Ifsingle.png "alt=" Wkiol1evdeihhdfpaabqmefctau994.png "src=" http://s3.51cto.com/ Wyfs02/m01/85/ec/wkiol1evdeihhdfpaabqmefctau994.png "/>
Dual Branch
if judgment condition; then
Branch code with true condition
Else
The condition is a false branch code
Fi
Example code:
1 #!/bin/bash
2
3 #Author: Wangjun
4 #Version: 1.0
5 #Create time:2016-08-13 20:00:00
6 #Description: Ifdouble test
7
8 Read-p "Please input a username:" Name
9 If ID $name &>/dev/null; then
echo "$name user exists,user ID: ' Id-u $name '"
One else
echo "$name user doesn ' t exist"
Fi
650) this.width=650; "title=" Ifdouble.png "src=" http://s1.51cto.com/wyfs02/M02/85/EC/ Wkiom1evd8lwcz5jaabbhv0mdku780.png "alt=" Wkiom1evd8lwcz5jaabbhv0mdku780.png "/>
Multi-Branch
if CONDITION1; Then
If-true
Elif CONDITION2; Then
If-ture
Elif CONDITION3; Then
If-ture
...
Else
All-false
Fi
Judge by condition, when the first encounter is a "true" condition, execute its branch, and then end the entire if statement
This article is from the "Love Firewall" blog, be sure to keep this source http://183530300.blog.51cto.com/894387/1837637
Shell script Programming--if statements