两个批处理主要是下面【等号】内的区别
1.这是符合我预期结果的代码,等号内的结果正确显示。- @echo off
- set egg=6
- set C_PATH=c:\KL500\C
- set D_PATH=d:\kl300\D
- echo cpath=%C_PATH%
- echo dpath=%D_PATH%
- if "%egg%"=="6" CALL :DZPATH "%C_PATH%" "%D_PATH%"
- echo =====================================
- set aaa=%dzdk1%
- echo aaa=%aaa%
- set bbb=%dzdk2%
- echo bbb=%bbb%
- set CEP=%dzdk1%%dzp1%
- set DGP=%dzdk2%%dzp2%
- echo CEP=%CEP%
- echo DGP=%DGP%
- echo =====================================
- pause
-
- :END
- goto:eof
-
- :DZPATH
- rem path1
- set dzdk1=%~d1
- set dzp1=%~p1
- set dzfn1=%~n1
- set dzfx1=%~x1
- rem path2
- set dzdk2=%~d2
- set dzp2=%~p2
- set dzfn2=%~n2
- set dzfx2=%~x2
- rem path3
- set dzdk3=%~d3
- set dzp3=%~p3
- set dzfn3=%~n3
- set dzfx3=%~x3
- rem path4
- set dzdk4=%~d4
- set dzp4=%~p4
- set dzfn4=%~n4
- set dzfx4=%~x4
- goto:eof
复制代码 显示的结果是
=====================================
aaa=c:
bbb=d:
CEP=c:\KL500\
DGP=d:\kl300\
=====================================
2.这个我多加了个 IF 把等号内的内容框起来后,echo显示的结果就不对了。
请教为什么会这样?是格式写错了吗?- @echo off
- set egg=6
- set C_PATH=c:\KL500\C
- set D_PATH=d:\kl300\D
- echo cpath=%C_PATH%
- echo dpath=%D_PATH%
- if "%egg%"=="6" CALL :DZPATH "%C_PATH%" "%D_PATH%"
- echo =====================================
- if "%egg%"=="6" (
- set aaa=%dzdk1%
- echo aaa=%aaa%
- set bbb=%dzdk2%
- echo bbb=%bbb%
- set CEP=%dzdk1%%dzp1%
- set DGP=%dzdk2%%dzp2%
- echo CEP=%CEP%
- echo DGP=%DGP%
- )
- echo =====================================
-
- pause
-
- :END
- goto:eof
-
- :DZPATH
- rem path1
- set dzdk1=%~d1
- set dzp1=%~p1
- set dzfn1=%~n1
- set dzfx1=%~x1
- rem path2
- set dzdk2=%~d2
- set dzp2=%~p2
- set dzfn2=%~n2
- set dzfx2=%~x2
- rem path3
- set dzdk3=%~d3
- set dzp3=%~p3
- set dzfn3=%~n3
- set dzfx3=%~x3
- rem path4
- set dzdk4=%~d4
- set dzp4=%~p4
- set dzfn4=%~n4
- set dzfx4=%~x4
- goto:eof
复制代码 显示的结果是:
=====================================
aaa=
bbb=
CEP=
DGP=
===================================== |