标题: 怎样可以用批处理参数的值来做变量的名称?(在纯dos下)
[打印本页]
作者: ekromay
时间: 2010-6-9 23:27
标题: 怎样可以用批处理参数的值来做变量的名称?(在纯dos下)
批处理里用参数1的值作为变量的名称而且设置值为aaa的话就是set %1=aaa(设%1为bbb)
但如果要读这个变量的值,该怎么办?
我以为这样可以,但是不行:
if "%%%1%%"=="aaa" echo aaa
这样执行时就会显示成if "%bbb%"=="aaa" echo aaa
我希望能把%bbb%也转义为bbb变量的值,该怎么做?
我的环境是在纯dos下的,不是2000,xp的cmd下,谢谢了
作者: gool123456
时间: 2010-6-10 04:33
DOS下就不知道了,你试试吧
@echo off&setlocal enabledelayedexpansion
call :test bbb
pause&goto :eof
:test
set %1=aaa
if "!%1!"=="aaa" echo is aaa.
作者: ekromay
时间: 2010-6-10 11:48
其实如果用输出文件的办法就可以
set %1=aaa
echo if "%%%1%%"=="aaa" echo aaa >tmp.bat
call tmp.bat
del tmp.bat
我想知道有没有别的更好的方法呢?我希望尽量不要输出文件,因为如果是echo那样的语句那倒还可以,如果是goto的话,批处理已经执行到别的文件上了,跳不回来的啊
作者: netbenton
时间: 2010-6-10 12:16
这样就可以跳转了,
@echo off
set %1=:sub
echo set %%1=%%%1%%>>tmp.bat
call tmp.bat abc
goto %abc%
:sub
echo 跳转成功
:end
[
Last edited by netbenton on 2010-6-9 at 16:17 ]