Batch FOR 的用法

 

1. setlocal enabledelayedexpansion -- 延迟环境变量扩展。

2. 延迟变量扩展中,要使用!来引用变量。

 

 

@echo off
setlocal enabledelayedexpansion 

FOR /F "delims=~" %%a IN ('findstr "1" fileName') DO (^
    set str=%%a
    echo !str:s1=s2!
)
 

 

 

for %%a in (debugRecorder*) do (
	echo %%a
)
 

 

 

@echo off

cd %~dp0

REM %%i INSTANCE_NAME
REM %%j INSTANCE_TYPE
REM %%k IP

FOR /F "eol=# tokens=1,2 delims==" %%i IN ('findstr "localPath" pathConfig.ini') DO (^
    set localPath=%%j
)
FOR /F "eol=# tokens=1,2 delims==" %%i IN ('findstr "remotePathWAS61" pathConfig.ini') DO (^
    set remotePath=%%j
)

FOR /F "eol=# tokens=1,2,3 delims=," %%i IN ('findstr "%1.*%2" InstanceConfig.ini') DO (^
    start upload.bat %%i %%k "%localPath%\%%j\%%i\*" "%remotePath%/%%i/config/"
)

 @echo off

echo ********************************************************************************

REM %1 INSTANCE_NAME
REM %2 IP
REM %3 LOCAL_PATH
REM %4 REMOTE_PATH

REM %%a IP
REM %%b TYPE
REM %%c USER
REM %%d PWD&SSH

FOR /F "eol=; tokens=1,2,3,4 delims=," %%a IN ('findstr "%2" serverConfig.ini') DO (^
    REM if %%b EQU SSH echo INSTACNE:%1 && pscp -i %%d -p -r %3 %%c@%%a:%4 && plink.exe -i %%d %%c@%%a chmod -R 777 %4* || goto Failure
    if %%b EQU SSH echo INSTACNE:%1 && pscp -i %%d -p -r %3 %%c@%%a:%4 || goto Failure
    if %%b EQU PWD echo INSTACNE:%1 && pscp -p -r -pw %%d %3 %%c@%%a:%4 || goto Failure)
)

echo Upload completelly!
echo ********************************************************************************

exit

:Failure
echo Upload failed!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值