Within a batch file, echo the literal string %something% to another file, rather than the variable expanding

Hi,

From a batch file, I was wondering how I can echo the literal string %something% to a file, rather than the variable expanding and the value of the variable being echoed to the file.

Thanks
Matthew
LVL 16
Matthew MillersAsked:
Who is Participating?
 
oBdACommented:
You actually only need double pecent signs:
echo %%variable%% >> log.txt
The caret is required to echo/escape other special characters, like < > | ( ) &
In addition, I'd recommend to put the echo at the beginning, it prevents the lines in the text file ending with a space:
>>"log.txt" echo %%variable%%
0
 
yehudahaCommented:
like this ?

echo %variable% >> log.txt
0
 
Matthew MillersAuthor Commented:
Not really, that would either put nothing in the output file or expand the variable %variable% and put the current value into the output file.

What i actually want to do is literally output %variable% into the output file.

So....
echo %variable% >> log.txt

log.txt would contain
%variable%

Rather than
ValueofVariable
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
Matthew MillersAuthor Commented:
Hi,

Worked it out.

^%%VARIABLE^%%  >> textfile

SO textfile contains
%VARIABLE%

Thanks for your efforts.

Matthew
0
 
yehudahaCommented:
no problem
0
 
Matthew MillersAuthor Commented:
HI,

I tried the %%variable%% and it actually placed the %%variable%% into the output file!

THanks very much for the echo advice, I will use that from now on.

Matthew
0
 
oBdACommented:
Did you try that on the command line?
There is a slightly different behavior between echo in the command window and a batch script.
In a script, you normally need two percent signs to echo one.
0
 
t0t0Commented:
what's your purpose for doing this?
0
 
Matthew MillersAuthor Commented:
Hi,

I was writing a script where I could parse a number of disk GUIDs and call the diskshadow program to snap the volumes off for backup purposes. The diskshadow program does not recognise system variables as it uses its own aliases.

Part of the command sequence is to create a alias using %alias%, hence the question.

I have finished the script now anyway, so all good!

Thanks
Matthew
0
 
t0t0Commented:
makes sense. you seem to know what you're doing.... glad y ou got there!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.