Control statements executed by bash scripts

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.