0

Code first:

ECHO off
SET home       = c:\Cygwin\home\ian
SET update_log = %home%\update.txt
                 ^^^^^^

Is there a way to prepend the %home% variable in the initialization of update_log variable as in the example shown above?

aschipfl
  • 33,626
  • 12
  • 54
  • 99
101010
  • 41,839
  • 11
  • 94
  • 168
  • [The Windows command prompt is *NOT* a DOS prompt!](https://scalibq.wordpress.com/2012/05/23/the-windows-command-prompt-is-not-a-dos-prompt/) – aschipfl Mar 21 '17 at 17:17

2 Answers2

6
  • Spaces on the left side of the equal sign are included in the variable name.
  • Spaces on the right side of the equal sign are included in the variable value.

If the spaces in these places are not a requirement, don't use them

SET "home=c:\Cygwin\home\ian"
SET "update_log=%home%\update.txt"

Also, it is recomended to quote the assignments to prevent problems with special characters and to avoid the inclusion of spaces at the end of the value.

MC ND
  • 69,615
  • 8
  • 84
  • 126
4

Exactly as you have it, except batch is sensitive to spaces in a SET statement. SET FLAG = N sets a variable named "FLAGSpace" to a value of "SpaceN"

The syntax SET "var=value" (where value may be empty) is used to ensure that any stray trailing spaces are NOT included in the value assigned. set /a can safely be used "quoteless".

So - remove the spaces

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • set /a can safely be used "quoteless" - as long no: logical shift, bitwise and, bitwise or, assignments with the previous operators are involved. –  Mar 25 '17 at 00:46