In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the specific usage of cmd if condition. Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn the specific usage of cmd if condition.
1. Determine whether the drive, file or folder exists, using the if exist statement;
2. To determine whether two strings are equal, use if "string 1"=="string 2" statement;
3. Determine whether two values are equal, and use if value 1 equ value 2 statement;
4. To determine whether a variable has been assigned, use the if defined str statement;
The complete form of an if statement is as follows: If the conditional expression (statement 1) else (statement 2), it means: If the conditional expression holds, then statement 1 is executed, otherwise statement 2 is executed.
For each of the above four cases, the following code can be used:
1, if exists d:\test.txt (echo D disk has test.txt exists) else (echo D disk does not exist test.txt)
2, if "abc"=="xyz" (echo string abc equals string xyz) else (echo string abc does not equal string xyz)
3, if 1 equ 2 (echo 1 equals 2) else (echo 1 does not equal 2)
4. if defined str (echo str has been assigned, its value is %str%) else (echo str value is empty)
When judging whether strings are equal, if will be case-sensitive. For example, a simple if statement will think that the string abc and the string Abc are not the same. If you don't want to be case-sensitive, you need to add the/i switch and use the format if /i "String 1"=="String 2"; in addition, the equal symbol is a continuous "==" instead of a separate "=."
To judge the relationship between two values, in addition to equal to equ, there are other relationship symbols. All relationship symbols applicable to if statements are shown in the following table:
Chinese Meaning Relational Symbol English Interpretation
Equ is equal to
gtr greater than
geq greater than or equal to
Less than LSS
less than or equal to leq
neq is no equal
The if statement also has a condensed form: the if conditional expression statement, which means that if the conditional expression holds, the statement will be executed, otherwise, nothing will be done.
Examples:
Save the following as a BAT file
The code is as follows:
@echo off
if exist e:\123.bat goto st
copy /y c:\123.bat e:\123.bat
goto st
:st
start e:\123.bat
exit
Description:
Judge whether the file exists, execute if it exists, copy the file to the target and execute if it does not exist. Can be changed as needed inside the file name, can be EXE, BAT, CMD, COM and other executive files.
BAT programming-choice command
choice command
The choice command allows the user to enter a single character to run different commands in the command format " choice [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]." The parameters have the following meanings:
/C choices Specifies the list of options to create. The default list is Y/N.
/N Hide the list of options from the prompt. Prompt The previous message gets displayed option is still enabled.
/CS allows case-sensitive options to be selected. By default, this tool is case-insensitive.
/T timeout The number of seconds to pause before making the default selection. Acceptable values range from 0 to 9999. If 0 is specified, there is no pause and the default option is selected.
/D choice Specifies the default option after n seconds. The character must be in the set of choices specified with the/C option; n must also be specified with/T.
/M text Specifies the message to display before prompting. If not specified, the tool displays only hints.
Example: Use of the choice command
Enter "choice /C YNC /M " in the command line window to confirm, press Y, press N, or press C to cancel. "", after running, the display is as shown in the figure.
At this point, I believe that everyone has a deeper understanding of the specific usage of cmd if condition. Let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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.