Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case statement and Loop statement in shell programming

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Case multi-branch statement

Case statement structure: execute different command sequences according to different values of variables

Case variable value in mode 1) command sequence 1; mode 2) command sequence 2;; *) default command sequence esac

";" indicates the end of a sentence.

The "if,else" statement applies to an interval range

"the case' statement is suitable for matching a fixed value

An example of the application of case statement:

1. Determine whether the input character is a number, letter, or symbol

two。 Judge whether the input performance is good or bad

Loop statement

The structure of the for statement: read different variable values to execute the same set of commands one by one

For variable name in value list do command sequence done

Take a value from the list of values from top to bottom to assign a value to the variable, and then output

An example of the Application of for sentence

1. Add users in batch

The user name is stored in the users.txt file, one per line

The initial passwords are all set to 123456

Validate script

two。 Use the ping command to view connectivity to each host

Save the results to shuju.txt

The structure of the while statement: repeatedly test a condition and execute it repeatedly as long as the condition is established

While conditional Test Action do Command sequence done

An example of the application of while statement:

1. Add users in batch

The user name begins with stu and is numbered in numerical order

Add a total of 20 users, namely stu1, stu2, … 、 stu20

The initial passwords are all set to 123456

The structure of the until statement: test a condition repeatedly, and execute it repeatedly as long as the condition is not valid

Until conditional Test Action do Command sequence done

An application example of until sentence

1. The sum of 1-50 is calculated by cyclic accumulation.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report