Windows Batch Scripts

Some simple examples:

simple.bat

@echo off 
set _var1=3
set _var2=5
set /a _result=%_var1%+%_var2% 
echo Result is %_result%                

 

mult.bat

@echo
off if "%1" == "" goto :help if "%2" == "" goto :help set /a result=%1 * %2 echo Result is %result% goto :eof :help echo Usage: mult X Y (Multiply X by Y)

 

power.bat

@echo off
if "%1" == "" goto :help
if "%2" == "" goto :help
set _result=%1
for /L %%G in (2,1,%2) do set /a "_result*=%1"
echo %1 to the power of %2 is %_result%
goto :eof

:help
echo Usage: power X Y (Calculate X to the power of Y.)

 

functions.bat

@echo off
set /p _num1=Number1: 
set /p _num2=Number2: 
call :plusfunc %_num1% %_num2%
call :output
call :subfunc %_num1% %_num2%
call :output
goto :eof

:plusfunc
setlocal
set /a _num1=%1 + %2
endlocal & set _result=%_num1%
goto :eof

:subfunc
setlocal 
set /a result=%1 - %2
endlocal & set _result=%result%
goto :eof


:output
echo Result is %_result%
goto :eof

 

转载于:https://www.cnblogs.com/roronoa-sqd/p/5396509.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值