0

I am new to batch programming, currently facing one issue in below batch script.

REM 

SET Var1=10
SET Var2=20

SET Var3 = john

SET Var4 = john1

ECHO variable values

ECHO %Var1%
ECHO %Var2%
ECHO %Var3%
ECHO %Var4%

for /f "tokens=1,2 delims=\\ " %%a in ("%1") do set component=%%a&set app=%%b

pause
EXIT

The issue is as stated below,

the statements ECHO %Var3%, ECHO %Var4% ==> won't produce the desired result which is to print the string value they are assigned to. Instead in prints ECHO ON.

Not sure what is the issue. I know it is trivial please help.

2 Answers 2

0

%var3% not equal to %Var3%. So, your %Var3%==" john" and your %var3%=="". When you call echo with empty parameter, it prints current echo mode (on or off).

Also SET Var3 = john is not equal to SET Var3=john. First command means 'create variable "Var3 " (i.e. it's name consists of 5 characters - fifth is space) with value " john"' (it's values starts with space). Try to add following lines in your script to see it:

ECHO %Var3 %
ECHO %Var4 %
7
  • TO be specific the numerical values are ECHOed correctly but the issue is with string data
    – suhel
    Jun 27, 2014 at 10:18
  • Thanks for ur answer, one question, what does SET Var3=john mean?. means how different from SET Var3 = john.
    – suhel
    Jun 27, 2014 at 10:25
  • Also one more doubt, in statement, for /f "tokens=1,2 delims=\\ " %%a in ("%1") do set component=%%a&set app=%%b what would be the value of app, if input to the batch is just the string, hi .
    – suhel
    Jun 27, 2014 at 10:28
  • I know that i would be equivalent to "SET app=" is it possible to check using IF statement if the value in "app""is a valid string or not?
    – suhel
    Jun 27, 2014 at 10:32
  • What does 'valid string' mean?
    – Ilya
    Jun 27, 2014 at 10:32
0

Here is a good method to echo a blank line when the variable is empty, or otherwise echo the variable.

ECHO(%Var1%

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.