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 > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Bat:
Batch is a simplified scripting language, also known as macros. It is used in DOS and Windows systems. It is a command interpreter embedded in DOS or Windows systems (usually COMMAND. COM or CMD.EXE) explain and run. Similar to the Shell script in Unix. Batch files have .bat or .cmd extensions, and the simplest example is the various commands that are used on the command line one line at a time. In more complex cases, it is necessary to use commands such as if,for,goto to control the running process of the program, just like the medium-and high-level languages such as Cmeme basic. If you need to implement more complex applications, it is necessary to use external programs, including external commands provided by the system itself and tools or software provided by third parties. Batch files, or batch programs, are plain text files made up of DOS commands, which can be edited directly with notepad, created with DOS commands, or edited with Edit.exe, a text editor under DOS. Type the name of the batch file at the Command prompt, or double-click the batch file, and the system calls Cmd.exe to run the batch program. In general, each command occupies one line; of course, multiple commands can be separated by specific symbols (such as: &;, & &;, |, |, etc.) and written on the same line; in other cases, higher-level commands such as if and for take up several lines, dozens or even hundreds of lines of space. When the system interprets and runs the batch program, it first scans the entire batch program, and then executes all commands step by step from the first line of code until the end of the program or encounters an exit command or exits unexpectedly.
Echo [{on | off}] [message]
Sample:@echo off / echo hello world
Rem [comment content]
Example: Hello, rem.
There is still a difference between:: and rem. When echo is turned off, the contents of rem and:: will not be displayed. However, when the echo is turned on, the content after rem will be displayed, however, the content after:: will still not be displayed.
Pause this command displays the following message:
Press any key to continue. . . (or: press any key to continue. . (.)
Call calls one batch program from another without terminating the parent batch program.
Call [path file name] [label]
Start calls external programs, and all DOS commands and command-line programs can be called by the start command.
For example, start calc.exe can open Windows's calculator.
Goto jump command. The program pointer jumps to the specified label and continues to execute the batch program starting with the first command after the label
Example:
: 1
Start
Goto 1
Note: a lot of windows will be opened (used to make people quite good). Open the window with the start command, and then use the goto 1 command to go to the 1 tab. Note that the label name should be preceded by an English colon.
Set displays, sets, or deletes variables. Variables in a batch are indistinguishable from type
Example:
The value of the set aa=345 # # variable aa can be regarded as either the number 345 or the string 345
Command "setlocal enabledelayedexpansion" to turn on the delay variable switch
@ echo mask, which means that the commands after @ are not displayed
>, > > (output redirection)
Logical command characters include: &;, & &;, | |
&: used to connect n DOS commands and execute them sequentially, regardless of whether or not any of the commands failed
& &: when the previous command is executed successfully, execute the following command, but if the previous command fails, it will not be executed later.
| |: when the previous command fails, execute | | subsequent command, otherwise no subsequent command will be executed
If statement:
(1) string comparison
IF [not] string1 compare-op string2 command1 [else command2]
There are several categories of compare-op:
=-equals
EQU-equals
NEQ-not equal to
LSS-less than
LEQ-less than or equal to
GTR-greater than
GEQ-greater than or equal to
Note: select switch / I is not case sensitive; select not item, the result is logically negative.
Example: if% str1%==%str2% (same echo string!) Else (the echo string is different!)
If / I% str1% LSS% str2% (echo str1 ^ = str2)
Interactive:
Echo.
Does set / p choice= display the current time? (YBO)
If / I not% choice% EQU n echo current time is:% date%% time%
Pause > nul
(2) existence judgment
IF [NOT] EXIST filename command1 [else command2]
Example:
@ echo off
If exist 0 echo file 0 exists!
If not exist% ~ df0 (
Echo folder% ~ df0 does not exist!
) else echo folder% ~ df0 exists!
Pause > nul
Note: existence judgment can judge both files and folders, and the format is strictly above (% 0 represents the full name of the batch, and% ~ df0 is a correction to% 0, leaving only its drive letter and path).
(3) define judgment (judge whether the variable exists)
IF [not] DEFINED variable command1 [else command2]
Example:
@ echo off
Set var=111
If defined var (echo var=%var%) else echo var has not been defined!
Set var=%%
If defined var (echo var=%var%) else echo var has not been defined!
Pause > nul
(4) result judgment
For statement:
(1) No switch
FOR variable IN (set) DO command
Example: for% I in (a, "b c", d) do echo% I
Note:%% variable is the writing format in the batch program, written as% variable in DOS, that is, there is only one% sign (%)
(2) switch (both upper and lower case)
FOR / L% variable IN (start,step,end) DO command # # / L can control the number of cycles according to start, step, end
FOR / F ["options"]% variable IN (set) DO command # / F
# # switch / D list all files / R traversal folders
String:
= =
@ echo off
Set ifo=abcdefghijklmnopqrstuvwxyz0 12 3456789
Echo original string (the serial number of each character in the second behavior):
Echo ifo%
Echo 1234567890123 45678901234567890123456
Echo intercepts the first five characters:
Echo ifo:~0,5%
Echo intercepts the last five characters:
Echo ifo:~-5%
Echo intercepts the first character to the penultimate character:
Echo ifo:~0,-5%
Echo starts with the fourth character and intercepts five characters:
Echo ifo:~3,5%
Echo starts with the penultimate 14 characters and intercepts 5 characters:
Echo ifo:~-14,5%
Pause
= =
= =
@ echo off
Echo current time is:% time%, that is,% time:~0,2% point% time:~3,2% minute% time:~6,2% second% time:~9,2% centisecond
Pause
= =
Replacement string
= =
@ echo off
Set aa= Great China! I'm proud of you!
Before echo replacement:% aa%
After echo replacement:% aa: China = people's Republic of China%
Echo aa =% aa%
Set "aa=%aa: China = people's Republic of China%"
Echo aa =% aa%
Pause
= =
String merging
@ echo off
Set aa= Great China!
Set bb=, I'm proud of you!
Echo aa%%bb%
Echo aa=%aa%
Echo bb=%bb%
Set "aa=%aa%%bb%"
Echo aa=%aa%
Pause
Extended string
= =
~ I-remove any quotation marks ("), expand% I
% ~ fI-extends% I to a fully qualified pathname
% ~ dI-expand% I to only one drive letter
% ~ pI-extends% I to only one path
% ~ nI-extends% I to only one file name
% ~ xI-extends% I to only one file extension
% ~ sI-the extended path contains only short names
% ~ aI-extends% I to the file attributes of the file
% ~ tI-extends% I to the date / time of the file
% ~ zI-extends% I to the size of the file
% ~ $PATH:I-find the directory listed in the path environment variable and extend% I
To the first fully qualified name found. If the environment variable name
If the file is not defined, or the file is not found, this key combination will be extended to
Empty string
You can combine modifiers to get multiple results:
% ~ dpI-extends% I to only one drive letter and path
% ~ nxI-extends% I only to a file name and extension
% ~ fsI-only extends% I to a full pathname with a short name
% ~ dp$PATH:i-find the directory listed in the path environment variable and extend% I
To the first drive letter and path found.
% ~ ftzaI-extends% I to DIR with similar output lines
= =
Note:% 0 is a parameter in the batch and represents the full path of the currently running batch. Similarly, there is% 1mi% 9, which represents the first-ninth parameters passed.
Character calculation
= =
()-grouping
! ~-- unary operator (logical non, bitwise non, negative)
* /%-arithmetic operator (multiplication, division quotient, division remainder, that is, remainder)
+-arithmetic operators (addition, subtraction)
>-logical shift (one bit to the left, one bit to the right)
&-bitwise "and"
^-bitwise "different"
|-Bitwise "OR"
= * /% = + =-- assignment
& = ^ = | =
,-expression separator (set can process more than one expression at a time)
= =
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.