0

I have a batch script as follow:

setlocal enabledelayedexpansion
for /f "tokens=1,2 skip=3 delims= " %%a in (Instance_list.txt) do (
Set Intance_NAME=%%a
echo %Intance_NAME%

But The echo part is empty(Nothing).
Could you please tell me why and help me with this?

Rishav
  • 3,818
  • 1
  • 31
  • 49
DBALUKE HUANG
  • 247
  • 1
  • 10
  • 3
    You have delayed expansion enabled but you are not referencing the variable correctly. You need to use exclamation points instead of percent symbols. – Squashman May 25 '18 at 15:54

1 Answers1

1

Couple of things:

You activate delayedexpansion but never use it (see the replacement of % in the last line with !

You also do not need to use `"delims= " on whitespace as whitespace are default delimiters in batch.

You did not close the loop with a closing (

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 skip=3" %%a in (Instance_list.txt) do (
Set Intance_NAME=%%a
echo !Intance_NAME!
)

and lastly, you do not really need delayedexpansion if you do not set the variable inside the loop, so you could also do:

@echo off
for /f "tokens=1,2 skip=3" %%a in (Instance_list.txt) do echo %%a
Gerhard
  • 22,678
  • 7
  • 27
  • 43