In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the example usage of dos if conditional judgment sentence". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the example usage of dos if conditional judgment sentence.
1. To determine whether a drive, file or folder exists, use the if exist statement
2. To determine whether two strings are equal, use the if "string 1" = = "string 2" statement
3. To judge whether two values are equal, use if numerical value 1 equ numerical value 2 statement
4. To determine whether a variable has been assigned, use the if defined str statement
The complete format of the if statement is as follows: if conditional expression (statement 1) else (statement 2), which means that if the conditional expression holds, then statement 1 is executed, otherwise statement 2 is executed.
For the above four cases, you can use the following code:
1. If exist d:\ test.txt (test.txt exists under echo D) else (test.txt does not exist under echo D)
2. If "abc" = = "xyz" (echo string abc equals string xyz) else (echo string abc is not equal to string xyz)
3. If 1 equ 2 (echo 1 equals 2) else (echo 1 is not equal to 2)
4. If defined str (the echo variable str has been assigned to% str%) else (the value of the echo variable str is empty)
When judging whether a string is equal, if will be case-sensitive. For example, a simple if statement will think that the string abc is different from the string Abc. If you do not want to be case-sensitive, you need to add a / I switch, using the format of if / I "string 1" = = "string 2"; in addition, the equal symbol is a continuous "=" rather than a separate "=".
To judge the size relationship between two values, in addition to using equ, there are other relation symbols, all of which are applicable to if statements as shown in the following table:
Chinese meaning relation symbol English interpretation
Equal to equ equal
Greater than gtr greater than
Greater than or equal to geq greater than or equal
Less than lss less than
Less than or equal to leq less than or equal
Not equal to neq no equal
The if statement also has a simplified format: the if conditional expression statement, which means that if the conditional expression is valid, the statement will be executed, otherwise, nothing will be done.
Learning if conditional statements
Key points of study:
The basic syntax of five if statements:
one. To determine whether two strings are equal, if "string 1" = = "string 2" command statement
two. To determine whether two values are equal, if value 1 equ number 2 command statement
three. Determine whether a drive, file, or folder exists, if exist filename command statement
four. Determine whether the variable has been defined, if defined variable command statement
five. Determine the return value of the last command, the if errorlevel numeric command statement.
-
one. To determine whether two strings are equal, if "string 1" = = "string 2" command statement
Note: in "string 1" = "string 2", there are two consecutive "="
Example 1
@ echo offset / p var1= Please enter the first comparison character: set / p var2= Please enter the second softer character: if "% var1%" = = "% var2%" (the two characters entered by echo are the same) the two characters entered by else echo are different pause
After execution, you will be asked to enter two strings, and then batch to determine whether the two are the same. When determining whether strings are equal, if is case-sensitive
Yes, please take a look
Example 2
@ echo offif "a" = = "A" (two characters entered by echo are the same) two characters entered by else echo are not the same pause
After execution, it will be displayed that the two characters entered are different.
If we don't want it to be case-sensitive, we can add the / I parameter. Take a look at the following example
Example 3
@ echo offif / I "a" = = "A" (two characters entered by echo are the same) two characters entered by else echo are not the same pause
After this execution, it will be displayed: the two characters entered are the same
-
two. To determine whether two values are equal, if value 1 equ number 2 command statement
The equ in the statement means equality, and the following relation symbols are used to judge the size relationship between the two values:
Chinese meaning relation symbol English interpretation
Equal to equ equal
Greater than gtr greater than
Greater than or equal to geq greater than or equal
Less than lss less than
Less than or equal to leq less than or equal
Not equal to neq no equal
Let's look at an example.
Example 4
@ echo off set / p var= Please enter a number: if% var% geq 10 (echo is greater than or equal to 10) else echo this number is less than 10pause
Note that the greater than sign, less than sign, equal sign and so on in batch processing cannot be used: ">"
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.