Introduction to common batch internal commands

Source: Internet
Author: User
Tags echo command

Echo " Welcome to the very bat! " Pause
Simpleexample

Save the above code in bat or CMD format, and double-click to run will display the following two lingo on the screen:

Welcome to the very bat!
Please press any key to continue ...

Common commands:

1

REM and::

REM is a comment command, after which the contents of the command are not executed, but can be echoed.
:: Can also act as an annotation, but there are 2 points:
① any word that begins with: lines is treated as a label in the batch, ignoring all subsequent contents.
Valid designator:: followed by a string preceded by an alphanumeric, the Goto statement can be identified.
Invalid Label:: followed by a non-alphanumeric special symbol, goto unrecognized label, can play the role of annotation, so::
is often used as an annotation symbol, in fact: + can also play an annotated role.
Unlike REM, ②: The post-character lines is not echoed at execution time, regardless of whether you open the command-line echo state with Echo on, because
The command interpreter does not consider him to be a valid command line; In addition, REM can be used for Config.sys files.
In-line comment:% Note content% (infrequently used, caution)

2 ECHO and @

The @ character is closed before the command is echoed, regardless of whether Echo is turned on.
The function of the echo command:
① turn on/off echo function
Format:echo [{On|off}]
If you want to turn off the display of the ECHO off command line itself, you need to precede the command line with "@".
② Display the current echo settings status
Format:Echo
③ OUTPUT hint Information
Format:ECHO Information Content
④ Close the DOS command prompt
Type in the DOS prompt stateECHO OFF, you can turn off the display of the DOS prompt so that the screen leaves only the cursor until you type
ECHO on, the prompt will not appear again.
⑤ outputs a blank line, which is equivalent to entering a carriage return
Format:ECHO.(. You can't have spaces in the middle of the echo, otherwise.) will be treated as a message output. Another. Available,:; "/[\]+, etc. any symbol substitution)
Command echo. The output of the return, the DOS pipeline steering can be used as input to other commands, such as echo.| Time is equivalent to giving a carriage return after the time command executes. Therefore, the system will automatically return to the DOS prompt after the current time is displayed.
⑥ reply to a question in the command
Format:ECHO Reply | command file name
It can be used to simplify the operation of some commands that require man-machine dialogue (e.g. Chkdsk/f;format Drive:;del * *),
It is the input to the man-machine Dialogue command by a DOS pipeline command to output the echo command in the preset reply. The following example is equivalent to entering a "Y" carriage return when a conversation occurs in a invoked command:
C:>echo y| chkdsk/f
C:>echo y| DEL A:*. *
⑦ Create new File/Add File contents
Format:echo File contents > FileName echo File contents >> file name
C:>echo @ECHO off>autoexec. BAT to create an automatic batch file
C:>echo c:\cpav\bootsafe>>autoexec. BAT appends content to an automatic batch file
C:>type AUTOEXEC. BAT displays the automatic batch file
⑧ Print content/print control code to printer
Format:ECHO Printer control code >PRN    ECHO Print Content >prn
The following example is a print control code that is entered into the M-1724 printer. <Alt> 156 is to hold down the ALT key on the keypad, type 156, and so on:
C:>echo +156+42+116>prn (Input underline command fs*t)
C:>echo [Email protected]>prn (Input initialization command [email protected])
C:&GT;ECHO.&GT;PRN (line wrapping)
⑨ the horn.ECHO ^g
"^g" is a ctrl+g or alt+007 input in a DOS window, and multiple ^g can produce multiple beeps. The way to use it is to directly
Called in a batch file or made into a batch file.

3 PAUSE

Stops the execution of the system command and displays the following content.
Example:PAUSE
Run Display:
Please press any key to continue ...
To display additional prompts, you can use:
Echo Other Tips & Pause > nul

4 ERRORLEVEL

Program return code
Echo%errorlevel%
Each command runs the end, can use this command to view the return code, to determine whether the command was executed successfully, the default is 0, General Command execution error will be set ERRORLEVEL to 1

5 TITLE

Set the title of the cmd window
title new Headline #可以看到cmd窗口的标题栏变了

6 color 

Sets the default console foreground and background color.

7 Mode

Configure the system device.
Serial port: MODE comm[:] [baud=b] [parity=p] [Data=d] [stop=s]
[To=on|off] [Xon=on|off] [Odsr=on|off] [Octs=on|off] [DTR=ON|OFF|HS] [RTS=ON|OFF|HS|TG] [Idsr=on|off]
Device status: MODE [device] [/status]
Print redirection: MODE lptn[:]=comm[:]
Selected code page: MODE con[:] CP select=yyy
code page Status: MODE con[:] CP [/status]
Display mode: Mode con[:] [cols=c] [lines=n]
Keystroke rate: MODE con[:] [rate=r Delay=d]
Cases:
Mode con cols=113 lines=15 & Color 9f
This command sets the DOS window size: 15 rows, 113 columns

8 GOTO and:
9 FIND
10 START
11 Assoc and Ftype
12 Pushd and POPD
13 Pager
14 Shift
15 IF
16 setlocal and variable delay
17 ATTRIB Display or change file properties

Introduction to common batch internal commands

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.