[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1192
  • Last Modified:

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
0
Matthew Millers
Asked:
Matthew Millers
  • 4
  • 2
  • 2
  • +1
1 Solution
 
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
 
Matthew MillersAuthor Commented:
Hi,

Worked it out.

^%%VARIABLE^%%  >> textfile

SO textfile contains
%VARIABLE%

Thanks for your efforts.

Matthew
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
yehudahaCommented:
no problem
0
 
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
 
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now