Solved

How to set a DOS batch variable to a single space

Posted on 2010-11-19
4
931 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 54

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 54

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

680 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