1

I've just started with batch file programming and testing variable usage momentary.

Does anyone know what is the difference between the 2 variable calls, the space before the last %

@echo off
set pathOS1="\\o1511\Pcs7ProjectO1511\OS1511\GraCS\"
ECHO We're working with %pathOS1%
ECHO We're working with %pathOS1 %

since the echo is different:

We're working with "\\o1511\Pcs7ProjectO1511\OS1511\GraCS\"
We're working with \\o1511\Pcs7ProjectO1511\OS1511\GraCS\

Delayed expansion is not enabled.

Mofi
  • 46,139
  • 17
  • 80
  • 143
Stefan
  • 372
  • 1
  • 16
  • See also answer on [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](http://stackoverflow.com/a/26388460/3074564) – Mofi Jan 11 '15 at 17:33

2 Answers2

3

Spaces are allowed in the variable name.

set "data=100"
set "data =101"
echo %data%
echo %data %
set data

You have two variables with two similar values

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • But he has only one variable declaration not two. So the second `echo` commands shouldn't show anything because that variable is not defined –  Jan 11 '15 at 15:55
  • 2
    @a_horse_with_no_name : True, but since there's no `setlocal` at the start of the routine, any values `set` in the environment remain set, so if `"pathos1 "` was set previously, its value will be retained until it's cleared by a `set "pathos1 ="` statement or `cmd` is closed. I'd suggest the variable was previously set. @op: Using `setlocal` at the start of a routine (usually after `@echo off`) will back-out changes made to the environment by the routine when it ends. – Magoo Jan 11 '15 at 16:21
0

So I summarize your answers:

This can happen if there's no setlocal at the start of the routine, any values set in the environment remain set, so if "pathos1 " was set previously, its value will be retained until it's cleared by a set "pathos1 =" statement or cmd is closed.

So, since I didn't close the cmd and didn't set setlocal, I called the previously set variable "pathos1 =". It is good example for setlocal :)

Stefan
  • 372
  • 1
  • 16