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,151 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
 
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
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.

 
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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
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 …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

22 Experts available now in Live!

Get 1:1 Help Now