Windows shell脚本字符串搜索和替换变量

时间:2014-09-23 17:10:42

标签: windows batch-file

我有以下脚本:

setlocal ENABLEDELAYEDEXPANSION

set LOCAL_DIR=C:\wamp\www

set CLASS_NAME=%5
set TEST_NAME=%7

set CLASS_PATH=%6
set TEST_PATH=%8
set BOOT_PATH=%4

set CLASS_PATH=%CLASS_PATH:C:\wamp\www=/var/www%
set TEST_PATH=%TEST_PATH:C:\wamp\www=/var/www%
set BOOT_PATH=%BOOT_PATH:C:\wamp\www=/var/www%

echo phpunit-skelgen %1 %2 --bootstrap='%BOOT_PATH'

:C:\wamp\www\plink -batch -ssh -pw @dmin205 root@192.168.1.90 phpunit-skelgen %1 %2 --bootstrap=%BOOT_PATH '%CLASS_NAME' '%CLASS_PATH' '%TEST_CLASS' '%TEST_PATH'"

我正在尝试制作" C:\ wamp \ www"和" / var / www"变量,但当我做的事情停止工作......任何人都有任何想法?

我希望甚至能够以编程方式找出这些路径的位置,并将它们保存在Windows会话的生命周期环境中

编辑| %BOOT_PATH不会在最终的回声输出...

中呈现

1 个答案:

答案 0 :(得分:0)

@echo off
setlocal ENABLEDELAYEDEXPANSION

set "LOCAL_DIR=C:\wamp\www"

set "CLASS_NAME=%~5"
set "TEST_NAME=%~7"

set "CLASS_PATH=%~6"
set "TEST_PATH=%~8"
set "BOOT_PATH=%~4"



for  %%# in ( "CLASS_PATH" "TEST_PATH" "BOOT_PATH" ) do (
    for %%z in ("!%%~#!") do set "_path=%%~pnz\"
    set "%%~#=!_path:\=/!
) 

echo %CLASS_PATH%--%TEST_PATH%--%BOOT_PATH%
endlocal
exit /b 0

检查一下。据我了解,你想删除驱动器号并用反斜杠替换斜杠。