Page 1 of 1
How to create a variable that contains only a SPACE character?
Posted: 16 May 2020 13:37
by Arianax
Hi all,
How do I create a string variable that contains only a single SPACE character?
The above doesn't seem to do anything and the variable returns 'ECHO is OFF' when called with 'ECHO !Variable!'.
Do I need to use %Variable% instead?
Appreciated.
Re: How to create a variable that contains only a SPACE character?
Posted: 17 May 2020 03:04
by penpen
Although i prefer usually encapsulating the variable assignemnt in deoblequotes (needs extensions to be enabled, which should be the default on most systems), what you did above is indeed a valid way of creating an environment variable with a single space character.
The echo-command just doesn't like spaces only lines (including an empty line) and messes up the output. You could prove that by replacing the space character with another character that 'echo' has no issues with.
However one workaround were, you could use a round opening bracket for the delimiter between the echo command and its arguments:
Code: Select all
@echo off
setlocal enableExtensions
SET Variable=
set "Variable2= "
echo %Variable% %Variable2%
echo %Variable: =#% %Variable2: =;%
echo(%Variable% %Variable2%
goto :eof
penpen