Certainly! Here are some common formulae and functions related to batch scripting:
For Loop(对于循环):
for /L %%variable in (start,step,end) do command
for /L %%i in (1,1,10) do echo %%i
IF Statement(IF语句):
if condition (command) else (command)
if exist file.txt (echo File exists) else (echo File does not exist)
Variable Assignment(变量赋值):
set variable=value
set myVar=Hello
Command Line Arguments(命令行参数):
%1
, %2
, ...echo The first argument is %1
GOTO Statement(GOTO声明):
goto label
goto start
Functions (using call
)(函数,用于调用):
Formula: call :functionName arg1 arg2 ...
Example:Call it: call :myFunction
:myFunction
echo This is a function
exit /b
String Manipulation(字符串操作):
%variable:~start,length%
set myString=HelloWorld
then %myString:~0,5%
gives Hello
These are some fundamental elements of batch scripting. Let's practice by using these in a sentence: