批量给变量分配字母数字值 [英] assigning an alphanumeric value to a variable in batch

查看:33
本文介绍了批量给变量分配字母数字值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在批处理脚本中将字母数字值分配给一个变量.我尝试跟随一个,但出现错误.

I want to assign the alpha numeric value to one variable in Batch scripting. I tried following one but getting error.

setlocal
set test = \765514e2aad02ca658cc56cdb7884947 *E:\\test1
echo %test%
endlocal

Error:
C:\Users\bgannu>setlocal

C:\Users\bgannu>set   test = \765514e2aad02ca658cc56cdb7884947 *E:\\test1

C:\Users\bgannu>echo 0
0

C:\Users\bgannu>endlocal

推荐答案

set的语法为 set [[/a [expression]] [/p [variable =]]字符串] = 必须直接在变量之后,因此您需要更改:

The syntax for set is set [[/a [expression]] [/p [variable=]] string] The = has to be directly after your variable so you need to change:

set test = \765514e2aad02ca658cc56cdb7884947 *E:\\test1

收件人:

set test=\765514e2aad02ca658cc56cdb7884947 *E:\\test1

否则,变量名的末尾将有一个空格.您可以轻松地尝试以下方法:

Otherwise your variable name would have a space at the end. You can easily try this out:

> set bar = foo
> echo %bar%
%bar%
> echo %bar %
 foo

请注意,变量名称​​及其均带有空格.

Note that both the variable name and its content got a space.

这篇关于批量给变量分配字母数字值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆