Bat If Command common judgment Introduction _dos/bat

Source: Internet
Author: User
Tags error code goto

If command

If the condition is judged to be in compliance with the stipulated conditions, it is decided to execute different commands.

There are three different formats:

1), if "parameter" = = "string" command to be executed

If the parameter is equal to the specified string, the condition is set, the command is run, or the next sentence is run. (note is two equals)

If "%1" = = "A" format a:
if {%1}=={} goto noparms
if {%2}=={} goto noparms

2), if exist filename to execute command

If you have the specified file, the condition is set, run the command, or run the next sentence.
such as if exist Config.sys edit Config.sys

3), if errorlevel/if not errorlevel number of commands to be executed

If the return code equals the specified number, the condition is set, the command is run, or the next sentence is run.

if errorlevel 2 goto x2

DOS program will return a number to DOS, called error code ERRORLEVEL or return code, the common return code is 0, 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.