0

I'm learning batch script, i came across a section creating structure in array. This is the sample program given as example.When i try to execute, It is not working. Can someone explain me what is wrong script? Thanks in advance!

code:

@echo off
set len=3
set obj[0].name=Joe
set obj[0].id=1
set obj[1].name=Mark
set obj[1].id=2
set obj[2].name=mohan
set obj[2].id=3
set i=0
:loop
if %i% equ %len% goto :eof
set cur.name=
set cur.id=
for /f "usebackq delims==. tokens=1-3" %%j in ('set obj[%i%]') do (
    set cur.%%k=%%l 
)
echo name=%cur.name%
echo value=%cur.id%
set /a i=%i%+1
goto loop
2
  • 1
    "it is not working" in not a valid problem description. Commented Feb 26, 2018 at 6:30
  • Gerhard Barnard The problem is while printing name and value only name= and value = is printed the actual value for the name and value is empty Commented Feb 26, 2018 at 9:06

1 Answer 1

2
for /f "usebackq delims==. tokens=1-3" %%j in ('set obj[%i%]') do (

is wrong. There are two sorts of single quotes:

Either use the correct quotes ' (without usebackq):

for /f "delims==. tokens=1-3" %%j in ('set obj[%i%]') do (

or with usebackq use the ` quotes

for /f "usebackq delims==. tokens=1-3" %%j in (`set obj[%i%]`) do (
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.