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
  • 31,767
  • 12
  • 51
  • 89
101010
  • 40,441
  • 10
  • 90
  • 155
  • [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
  • 67,669
  • 7
  • 79
  • 118
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
  • 72,034
  • 7
  • 58
  • 78
  • 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