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

How to use Shell case statement

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to use Shell case sentences". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use Shell case sentences.

The case selection statement in the shell script can be combined with the read instruction to achieve a better interactive response operation. Case receives one or more parameters passed in by the read instruction, and then case makes a selection operation according to the parameters.

The case statement format is as follows: case value in mode 1) command1command2...commandN;; mode 2) command1command2...commandN;;esac

Case works as shown above. The value must be followed by the word in, and each pattern must end with a closing parenthesis. The value can be a variable or a constant. After the match discovers that the value matches a certain pattern, all commands begin to execute until;;.

The value detects each pattern that matches. Once the pattern matches, the corresponding command to match the pattern is executed and the other patterns are not continued. If there is no matching pattern, use the asterisk * to capture the value, and then execute the following command.

The following script prompts for 1 to 4 to match each pattern:

Echo 'enter a number between 1 and 4:' echo 'the number you enter is:' read aNumcase $aNum in1) echo 'you chose 1 / 4 / 2) echo' you chose 2 / 2 / 3) echo 'you chose 3 / 3 / 4 / 3) echo / 4 / 4 / 4 / echo / 4 / 4 / echo / 4 / 4 / 4 / 4 / echo /

If you enter different content, you will have different results, such as:

Enter the number between 1 and 4: you enter the number is: 3 you chose 3 thank you for reading, the above is the "how to use the Shell case sentence" of the content, after the study of this article, I believe we have a deeper understanding of how to use the Shell case sentence, the specific use of the situation also need to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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: 256

*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

Development

Wechat

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

12
Report