1. control statements executed by bash scripts:
1. sequential execution: by default, each statement is executed one by one.
2. Select execution: Branch, condition judgment, and execution of qualified branches.
If
3. Loop execution: the same piece of code is repeatedly executed for a limited number of times.
A. For: knows the number of cycles,
For var_name in list;
Do
Loop body
Done
For example, add three users cyclically; Xiaowang, Xiaoli, and xiaosun
#! /Bin/bash
For username in Xiaowang Xiaoli xiaosun;
Do
Useradd $ username
Done
List generation method:
Generate number: {start... end}, seq [start] [STEP] End
Example: generate 10 users, which are user101. .. user110
For username in 'seq 101 110 ';
Do
Useradd user $ username
Done
For example, delete the 10 users generated above and delete the user's home directory.
For username in {101... 110 };
Do
Userdel-r user $ username
Done
B. While:
C.:
Ii. Check the bash script syntax command: Bash-N script file
3. Execute the Script: Bash script file. You do not need to modify the execution permission of the file.
Control statements executed by bash scripts