In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article analyzes "how to analyze case statements in Linux shell". The content is detailed and easy to understand. Friends who are interested in "how to analyze case sentences in Linux shell" can follow the editor's idea to read it slowly and deeply. I hope it will be helpful to you after reading. Let's learn more about "how to analyze case statements in Linux shell" with the editor.
The first two articles have shared the for loop and the whlie loop, so how can you get less case? case is also a multi-branch conditional statement, but you can only judge one relational condition.
The syntax of the case statement is as follows:
Case $variable name in "value 1"); if the value of the variable is equal to value 1, execute program 1, value 2 ") if the value of the variable is equal to the value 2, execute program 2... Omit other branches... *) if none of the variables have the above values, execute this program;; esac
This statement requires attention to the following:
The case statement takes the values in the variable and compares them with the values in the body of the statement. If the values match, the corresponding program is executed; if the values do not match, the next value is compared in turn; if all the values do not match, execute the program in ")" ("" represents all other values).
Case statements begin with "case" and end with "esac".
After each branch, end with ";" (double semicolon), which represents the end of the program segment (don't forget).
Note that the multi-branch case conditional statement can only determine what the value in the variable is, unlike the multi-branch if statement, which can judge multiple conditions, so the multi-branch case conditional statement is more suitable for the case of single condition and multi-branch. For example, we often see in the system that please select "yes/no", or choose whether to execute the first option or the second option (fdisk command) in the output of the command. In these cases, using case is the most appropriate. Let's write an example of choosing "yes/no" with the following command:
[root@localhost ~] # vi shamp cascade. Cho yes # judge that the user enters read-p "Please choose yes/no:"-t 30 cho# to output "Please select yes/no" on the screen, and then assign the user's choice to the variable "yes" of the judgment variable "yes") # if it is yes echo "Your choose is yes!", execute Program 1 "no") # execute program 2 if it is no echo "Your choose is no!" #; *) # execute this program if it is neither yes nor no echo "Your choose is error!" #; esac
Explain the script idea: ask the user to enter yes or no, and output "Your choose is yes!" if you enter yes; "Your choose is no!" if you enter no; and "Your choose is error!" if you enter other characters.
On how to analyze the case statements in Linux shell to share here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.