Solved

How to set a DOS batch variable to a single space

Posted on 2010-11-19
4
940 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
[X]
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
4 Comments
 
LVL 56

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 56

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

624 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