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!