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,155 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 14

Expert Comment

by:yehudaha
ID: 24431467
no problem
0
 
LVL 84

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 84

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to run a batch process 16 50
How to add SLEEP  to my runner.bat script?? 4 55
How to batch remove spreadsheet password 19 241
Import filename in batch 2 36
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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

765 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