In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use judgment statements in Shell scripting. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Single branch if statement
Format: if judgment condition; then
Statement1statement2...fi
Second, double-branched if statement
Format: if judgment condition; then
Statement1statement2...elsestatementN...fi
Use a previously used script to illustrate this structure.
III. Multi-branch if statement
Format: if judgment condition 1 then
Statement1...elif judgment condition 2; thenstatement2...elif judgment condition 3; thenstatement3...elsestatement4...fi
IV. Case statement
Format: case variable in
PATTERN1) statement...;;PATTERN2) statement... ;; *) statement...;;esac
Because judging the structural statement is relatively simple, there is not too much explanation, just remember the structural usage of each sentence.
Supplement shell basic syntax
1.1.The beginning of shell file
The shell file must start with the following line (must be on the first line of the file):
#! / bin/sh
Symbol #! It is used to tell the system that the parameters behind it are the program used to execute the file. In this example, we use / bin/sh to execute the program.
When you edit a script, you must also make it executable if you want to execute it.
To make the script executable:
Run chmod + x filename so that you can run it with. / filename
1.2 comments
In shell programming, sentences that begin with # indicate comments until the end of the line. We sincerely recommend that you use comments in your program.
If you use comments, you can understand how the script works and how it works in a short period of time, even if you haven't used the script for a long time.
1.3 variables
In shell programming, all variables are made up of strings, and you don't need to declare them, just assign them, and apply them in the form of $+ variable names.
To assign a value to a variable, you can write:
A = "hello world"
Now print the contents of the variable a:
Echo "An is:" echo $a
Sometimes variable names are easily confused with other words, such as:
Num=2 echo "this is the $numnd"
This does not print out "this is the 2nd", but only "this is the", because shell searches for the value of the variable numnd, but this variable has no value. You can use curly braces to tell shell that we are printing the num variable:
Num=2 echo "this is the ${num} nd"
This will print: this is the 2nd
1.4 Environmental variables
Variables that have been processed by the export keyword are called environment variables. We don't talk about environment variables, because usually we just log in
Environment variables are used in the script.
Thank you for reading! This is the end of this article on "how to use the judgment sentence of Shell scripting programming". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.