Discussion forum for all Windows batch related topics.
- Posts: 2
- Joined: 06 Apr 2020 14:38
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?
- Posts: 1809
- Joined: 23 Jun 2013 06:15
- Location: Germany
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
set "Variable2= "
echo %Variable% %Variable2%
echo %Variable: =#% %Variable2: =;%