• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 950
  • Last Modified:

How to set a DOS batch variable to a single space

Hello,
I need to set a dos variable to a single space
set space=" "
does not work, nor does
set space=
Thank you
0
pdegregorio
Asked:
pdegregorio
  • 2
  • 2
1 Solution
 
Bill PrewCommented:
Do this:

SET "Space= "

~bp
0
 
pdegregorioAuthor Commented:
SET "space= "
echo %space% > temp.txt
echo testing >> temp.txt
echo %space% >> temp.txt
echo 123 >> temp.txt

Problem is temp.txt contains

ECHO is on.
testing
ECHO is on.
123

and I'd like it to contain

testing

123


0
 
Bill PrewCommented:
You can use a subtle capability of the ECHO command to get around that.  Try this test:

SET "space= "
echo.%space% > temp.txt
echo.testing >> temp.txt
echo.%space% >> temp.txt
echo.123 >> temp.txt

Open in new window

~bp
0
 
pdegregorioAuthor Commented:
Using the "echo." followed by text, variable or nothing works perfectly and is a nice general purpose solution. Thanks a lot.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now