Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理:通过一个变量的值访问另一个变量_Batch File_Variables_Scope - Fatal编程技术网

Batch file 批处理:通过一个变量的值访问另一个变量

Batch file 批处理:通过一个变量的值访问另一个变量,batch-file,variables,scope,Batch File,Variables,Scope,如果标题令人困惑,我深表歉意。以下是我的批处理脚本: set var=1 set ss=var rem // ss is mean to be string call :func %ss% goto :eof :func rem // I want to access to value 1 by using %1, which is ss 有什么办法吗?如果您能提供帮助,我将不胜感激。您可以使用延迟扩展 @echo off SETLOCAL ENABLEDELAYEDEXPANSIO

如果标题令人困惑,我深表歉意。以下是我的批处理脚本:

set var=1
set ss=var rem // ss is mean to be string
call :func %ss%
goto :eof

:func
    rem // I want to access to value 1 by using %1, which is ss

有什么办法吗?如果您能提供帮助,我将不胜感激。您可以使用延迟扩展

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set var=1
set ss=var rem // ss is mean to be string
call :func %ss%
goto :eof

:func
    REM I want to access to value 1 by using %1, which is ss
    set a=%1
    REM will output '1'
    echo !%a%! 

评估:
!%a%!=>!var!=>1

echo!%1!无需将参数分配给环境变量。您只需要
!%1!