dgo
dgo

Reputation: 3937

Batch file output does not work as expected

First, before it gets suggested, I have DELAYEDEXPANSION enabled globally via the registry, and I've tried enabling locally as well.

I'm trying to echo HTML preprocessing code into the batch file, and the following works as expected:

echo ^<!-- @include ./%b%/main.inc --^> >> search-%b%.inc 

For example, it echos <!-- @include ./criteria/main.inc --> into file search-criteria.inc

However, the following does not:

echo ^<!-- @include ./!b!/main.inc --^> >> search-!b!.inc 

While, I'd expect the result to be the same, what shows up in search-criteria.inc is <b/main.inc -->

What's happening here?

As a side note - Sublime seems to know there is an error in my syntax, because highlighting breaks after the first <. If I escape the first !, the highlighting starts working again, but the result is the same.

Upvotes: 1

Views: 29

Answers (1)

Magoo
Magoo

Reputation: 79983

Escape the first ! with a double-caret ^^!. Batch is interpreting -- @include ./ as a variable.

Upvotes: 3

Related Questions