1

I have used FOR /F to access the value in the file "last_bkp_date.txt" inside a batch file.

The result of %%a is okay, but i am unable to assign value to v_abc.

I have used set v_abc = before the for loop to especially delete / remove any past assignment done to this variable.

Can somebody help me on this?

@SETLOCAL EnableDelayedExpansion
@echo off

set v_abc =

FOR  /F "tokens=1 usebackq" %%a IN (last_bkp_date.txt) DO (  
  set v_abc =%%a
  echo value of a: %%a
  echo value of abc: !v_abc!
)

2 Answers 2

2

Simple rookie mistake of adding a space after a variable name (set v_abc =%%a).

You can fix it by either

  1. Changing set v_abc =%%a to set v_abc=%%a

    Or

  2. Changing echo Value of abc: !v_abc! to echo Value of abc: !v_abc !.

Simple.

Sign up to request clarification or add additional context in comments.

Comments

2

The syntax is SET variable=value. Your problem is the space between the variable name and the = sign.

Just try this

set v_abc=%%a

and voilà!

The reason for this is that in Windows environment variable names can contain spaces. But it is not recommended, so as an alternative solution to your problem you could access the variable including the space, this way

echo value of abc: !v_abc !

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.