Solved

How to set a DOS batch variable to a single space

Posted on 2010-11-19
4
917 Views
Last Modified: 2012-06-27
Hello,
I need to set a dos variable to a single space
set space=" "
does not work, nor does
set space=
Thank you
0
Comment
Question by:pdegregorio
  • 2
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 34176458
Do this:

SET "Space= "

~bp
0
 

Author Comment

by:pdegregorio
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.
testing
ECHO is on.
123

and I'd like it to contain

testing

123


0
 
LVL 53

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

~bp
0
 

Author Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

825 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