Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to set a DOS batch variable to a single space

Posted on 2010-11-19
Medium Priority
Last Modified: 2012-06-27
I need to set a dos variable to a single space
set space=" "
does not work, nor does
set space=
Thank you
Question by:pdegregorio
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 57

Accepted Solution

Bill Prew earned 2000 total points
ID: 34176458
Do this:

SET "Space= "


Author Comment

ID: 34176688
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.
ECHO is on.

and I'd like it to contain



LVL 57

Expert Comment

by:Bill Prew
ID: 34179751
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


Author Comment

ID: 34182817
Using the "echo." followed by text, variable or nothing works perfectly and is a nice general purpose solution. Thanks a lot.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question