How to run a command in a batch file containing quotation marks ("")?

I have a batch file that tries to run the following:

FOR /F "tokens=1" %%G IN ('git show --pretty="format:" --name-only 54173344ab18a7d8e9ff2614cca62b671c8c7e2a') DO echo %%G 

Which results in a git error "fatal: Invalid object name 'format'."

However, if I just put the command in a batch file, I get the output that I expect.

git show --pretty="format:" --name-only 54173344ab18a7d8e9ff2614cca62b671c8c7e2a

It produces:

Files/MyFiles/header.html
Files/MyFiles/foo.html

The problem is with quotation marks around "format:".

I tried to run away from them using "", but to no avail. I also tried ^. I tried using the usebackq parameter.

This loop also works if you take out the argument --pretty = "format:", but then I get a bunch of added text.

+4
source share
1 answer

, :

git show --pretty="format:" --name-only 54173344ab18a7d8e9ff2614cca62b671c8c7e2a >> out.tmp
FOR /F "tokens=1" %%G IN (out.tmp) DO echo %%G
del out.tmp

, out.tmp, , .

+1

All Articles