我有以下脚本可以在许多 JAR 中查找一个类。类名作为字符串参数传递。
set ARG=%1
for /R %G in (*.jar) do @jar -tvf %G | find %ARG% > NUL && echo %G
给我以下错误
> findClassInJar.bat "ContentPartition"
> set ARG="ContentPartition"
| was unexpected at this time.
> for /R G | find "ContentPartition" > NUL && echo G
如何修复此错误?
对于批处理文件中的循环变量,应使用 %%
而不是 %
。也就是说,将%G
替换为 %%G
.否则,它将被解释为参数。