views:

106

answers:

2

Hi All,

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
A: 

Lose the /A. the /A is used for arithmetic.

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

C:\test>echo %var%
\765514e2aad02ca658cc56cdb7884947 *E:\\test1
ghostdog74
even after removing /A also not working
+2  A: 

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

to:

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.

Bruce
+1 for the correct issue; I took the liberty of making the actual problem a little clearer.
Joey