Solved

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

Posted on 2009-05-20
10
1,154 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:mattee76
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 14

Expert Comment

by:yehudaha
ID: 24431246
like this ?

echo %variable% >> log.txt
0
 
LVL 16

Author Comment

by:mattee76
ID: 24431385
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
 
LVL 16

Author Comment

by:mattee76
ID: 24431437
Hi,

Worked it out.

^%%VARIABLE^%%  >> textfile

SO textfile contains
%VARIABLE%

Thanks for your efforts.

Matthew
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 14

Expert Comment

by:yehudaha
ID: 24431467
no problem
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 24431478
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
 
LVL 16

Author Comment

by:mattee76
ID: 24431511
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
 
LVL 83

Expert Comment

by:oBdA
ID: 24431783
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
 
LVL 16

Expert Comment

by:t0t0
ID: 24434542
what's your purpose for doing this?
0
 
LVL 16

Author Comment

by:mattee76
ID: 24434656
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
 
LVL 16

Expert Comment

by:t0t0
ID: 24434689
makes sense. you seem to know what you're doing.... glad y ou got there!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…

832 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