bat Symbol Description

 

netstat -an|findstr 139

ipconfig / All findstr IP

ipconfig / All | findstr physical address value selected line
ipconfig / all | findstr 192.168.1 * fuzzy value of the selected row.
ipconfig / All | findstr / r / i "preferred physical address" multi-value selected line
ipconfig / all | findstr / r / i "preferred physical address" | findstr 192.168.1 * multi-line option.

 

Society Notes

Write bat batch, too, to be used in functional annotation, this is the program for readability

 

In the batch process, there is a relatively common section annotation method:

    Start GOTO
     = may be multiple lines of text, which can be command
     = may contain redirection symbols and other special characters
     = they do not contain: start this line, it is a comment
    : start


In addition, there are various other forms of annotation, such as:
 
   1 :: annotation content (after the first colon can with any non-alphanumeric character)
    2, REM footnotes (not appear redirection symbols and pipe symbol)
    3, echo annotation content (redirection symbols and the symbol in the pipelines)> NUL
    . 4, IF not exist NUL annotation content (and not appear redirection symbols pipe symbol)
    5 ,: annotation content (prior comment text must be unique tag )
    6, annotation content%% (comment lines may be used between, and can not appear redirection symbols pipe symbol)
    . 7, goto label annotation content (may be used as described goto conditions and execution contents)
    8 ,: tag annotation content (can used to perform content label at the bottom segment)
---------------------
author: wh_19910525
source: CSDN
original: https: //blog.csdn.net/wh_19910525/ article / details / 8125762
Disclaimer: This article is a blogger original article, reproduced, please attach Bowen link!

1, shielding @ character echo command line
    2, the pilot symbol variable% batch
    3,> redirector
    4, >> redirector
    5, <,> & <& redirector
    . 6, | command pipeline at
    7, ^ escape character
    8, the combine command &
    9, the combine command &&
    10, the combine command ||
    11, "" character string delimiter
    12 ,, comma
    13 semicolon ,;
    14, () brackets
    15,! exclamation point
    16, the batch other special marker may be seen: (omitted)
        CR (0D) command line terminator 
        escape (1B) ANSI escape character pilot symbols 
        Space (20) the parameters used delimiter 
        Tab (09); = commonly used parameters delimiter 
        + COPY command file connector 
        * wildcard file? 
        / parameter switch pilot symbols 
        : pilot symbols tag batch

Without further ado, the lecturing

1, shielding @ character echo command

This character means in the batch is closed echoes the current row. We used to know a few lessons
ECHO OFF can be closed off echo the whole batch commands, but you can not turn off the ECHO OFF command, and now we add a @ ECHO OFF before this command, you can reach all the commands are not echoed requirements

2, pilot symbols variable batch%

The percent sign is not really strict orders, it is only in the batch parameters only (when used with more than%, will be described in detail later).
With reference variable% var%, external calling program parameters 1% to 9%, and so
passed to the batch% 0% 1% 2% 3% 4% 5% 6% 7% 8% 9% * as a command line parameter
% 0 batch file itself, including the full path and extension
% 1 the first argument
% 9 ninth parameter
% * All parameters from the beginning of the first parameter
parameter% 0 has a special function, you can call the batch itself in order to achieve the purpose of the batch cycle itself, you can also copy the file itself, and so on.
Example: The easiest way to copy files its own
copy% 0 d: \ wind.bat
Tip: add inline comments
% Notes content% (can be used as inline comments, can not appear redirection symbols and pipe symbol)
Why did this happen? At this point "footnotes" in fact, is treated as a variable, its value is empty, so only play the role of a comment, but this usage syntax error prone, generally do not.

3,> redirector

Output redirection command
of this character is meant to cover the transfer and his role is to pass the results to a range running back (behind can be a file, it can be the default system console)
    in the command line NT series, heavy oriented scope by the entire command line commands into a single statement, by the command separator &, &&, ||, and constraints limiting statement block.
For example:
using the command: echo hello> 1.txt will establish a file 1.txt, content is "hello" (Note end of the line by a space)
use the command: echo hello> 1.txt will establish a file 1.txt, content is "hello "(Note end of the line with no spaces)

4, >> redirector

Output redirection command
symbol roles and> somewhat similar, but the difference between them and transfer >> is appended at the end of the file, and> is covering
use ibid
same 1.txt do get examples of
using the command:

?
1
2
echo hello > 1.txt
echo world >>1.txt

At this time 1.txt as follows:
the Hello
world

5, <,> & <& redirector

These three commands are also piping commands, but they are generally not used, you need to know about ok, of course, if you want to examine, you can check for yourself information. (I have checked, the Internet still can not find the relevant information)
<input redirection command, the command reads input from a file, rather than read from the keyboard.

?
1
2
3
4
@ echo off
echo 2005-05-01>temp.txt
date <temp.txt
del temp.txt

This can be modified directly without waiting for the input current date
> &, the output is written to a handle input of another handle.
<&, And just> & contrary, to read input from a handle and writes them to the output of another handle.
Common Handle: 0,1,2, undefined handle: 3-9
1> NUL correct information output is disabled.
2> nul output an error message indicating the prohibition.
1 and 2 which are representative of the address of an (NT CMD called handles, MSDOS called device) input and output stream.
Handle 0: standard input stdin, keyboard input
handle 1: standard output stdout, to output a command prompt (console, code CON)
handles 2: standard error stderr, outputs to the command prompt window (console, code CON)
wherein the stdin may be <redirected, stdout may be> >> redirection.
We already know the contents of the text can be read for the command, but if you only need to read the first line of command with for a little trouble. The simplest way is as follows:

?
1
2
3
4
@ echo off
set /p str=<%0
echo %str%
pause

Run the batch file displays its first line: @echo off

6, | command pipe character

Format: The first command | The second command [| The third command ...]
The results of the first command as an argument to use the second command, remember unix in this way is very common.
For example:
dir c: \ | the Find "TXT"
The above command is: Find the C: \ all, and found TXT string.
FIND function please use the FIND / self-View?
When does the automatic formatting parameters format, I was so used to automatically format A disc
echo y | format a: / s / q / v: system
used format are know when to re-enter y to confirm whether the trays trays, plus echo y before this command and with the | character to the results echo y passed to the format command
so as to achieve the purpose of automatic input of y
(this command has dangers, Please be careful when testing)

7, the escape character ^

^ Is a special symbol <,>, & leading character, he will be a special function to remove more than three symbols in the command, only put them as symbols rather than use their special significance.
such as

?
1
echo test ^>1.txt

The result is: test> 1.txt
he did not append 1.txt years, huh, huh. Just shows up
In addition, the escape character can also be used as a line continuation symbol.
Here is a simple example:

?
1
2
3
4
5
6
@ echo off
echo 英雄^
是^
好^
男人
pause

Needless to say, their own try to understand.
Why escape character can play on the end of the line continuation character's role in it? The reason is simple, because the end of each row there is an invisible symbols, i.e., a carriage return, when the end of a line let escape character fails carriage return, thus acts as the continuous line.

8, the combine command &

Syntax: a first & second command command [& third command ...]
&, &&, || command combination, by definition, is the ability to combine a plurality of command When a command to execute. This batch script is allowed, and with a very wide range. Because batch recognition does not recognize the number of command line.
This notation allows two or more different commands in a row, when the first command fails, the command does not affect the back.
Here & sides command is executed sequentially, from front to back execution.
For example:
the dir Z: \ the dir & Y: \ & the dir C: \
or more commands are continuously displayed content z, y, c disc, whether the disc exists ignore

9, the combine command &&

Syntax: first command && second command [&& third command ...]
by this method may be performed multiple commands, the command execution error when it comes to subsequent commands will not be executed, if there has been no the error has been executed all the commands
of this order and on top of similar, but the difference is that, when the first command fails, the command will not execute behind
dir z: \ && dir y: \ && dir c: \

10, || command combination

Syntax: first command || second command [|| third command ...]
by this method may be performed multiple commands, when a command fails after the second execution command, when it comes to performing after the proper command behind the command is not executed, if the correct command does not appear it has been executed all the commands;

Tip: Use a combination with the command and redirect command must be noted that the priority of
pipeline command takes precedence over the redirect command, redirect command a higher priority than a combination of command
problem: the C drive and D drive files and folders listed to a.txt file. See Example:
dir c: \ && dir d: \> a.txt
so after performing a.txt, only D disc information! why? Because the combination of the priority command does not redirect command higher priority! So the phrase in the implementation of the Bank is divided into two parts: dir c: \ and dir d: \> a.txt, but not as you think two parts: dir c: \ && dir d : \ and> a.txt. To use a combination of command && reach the subject requirements, must write it so:
dir c: \> a.txt && dir d: \ >> a.txt
this way, according to the priority level, DOS will put that into two segments : dir c: \> a.txt and dir d: \ >> a.txt. In a few cases the difference eighteen special, worth a good study of taste.
Of course, here you can also use & Order (they want the truth about oh):
dir c: \> a.txt & dir d: \ >> a.txt
[This can also be used dir c: \; d: \ >> a. txt to achieve]

11, "" character string delimiter

Double quotes spaces are allowed in the string, a special directory can be entered by the following methods
CD "program files"
CD Progra. 1 ~
CD Pro *
The above three methods may enter the program files directory

12 ,, comma

Comma is equivalent to a space, in some cases, "" can be used as a space to make
such
dir, c: \

13 ,; semicolon

Semicolon, when the same command, with the target may be different; to isolate, but perform the same effect, such as an error occurs during execution, only returns the error report, but the program will execute. (Some people say that does not continue, in fact, the test will know)
For example:
dir c: \; d: \; E: \; z: \
above command is equivalent to
dir c: \
dir d: \
dir E: \
dir f: \
If z disk does not exist, operation display: the system can not find the specified path. Then terminate the execution of the command.
Example: dir c: \; d: \; e: \ 1.txt
above command corresponding to
the dir C: \
the dir D: \
the dir e: \ 1.txt
wherein file e: \ 1.txt does not exist, but e plate there is, there is error, but the command will execute.

why? If the target path does not exist, then the termination of execution; if there is a path, only the file does not exist, continue.
Say about that! You have any comments, please Huitie! BAT have any questions please go to the exchange zone posting! Improvement in the next section!

14, () parentheses

There are in parentheses batch programming in a special role, must be used in pairs left and right parentheses, brackets may include multi-line commands that will be seen as a whole, regarded as a command line.
    Brackets for common statements and if statement for nested loop or conditional statements, in fact, the parentheses () can be used alone, see examples.
Example:
Command: echo 1 & echo 2 & echo 3
can be written as:
(
echo. 1
echo 2
echo. 3
)
above the same effect as two way, both are considered to be a writing command line.
Note: This multi-command is regarded as a command line, if there was variable, on issues related to variable delays.

15,! Exclamation point

Nothing to say, in the variable delay problem, used to represent variable that should be expressed as% var%! Var !, see the previous command setlocal introduction.

Guess you like

Origin www.cnblogs.com/--3q/p/10936418.html
bat