Solved

How to set a DOS batch variable to a single space

Posted on 2010-11-19
4
894 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 51

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 51

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now