在批处理文件中编写循环的语法
我正在尝试为我经常执行的任务编写一个小批处理文件。我以前从未使用过for
,这是我第一次尝试这个。这就是我到目前为止所得到的:
for /f %i in ('ct find . -ver lbtype(%1) -print') do ct lsvt -g %i
基本上它会尝试查找具有给定 cleracase 标签的所有文件,然后显示这些文件的版本树。问题出在 %1
中。但是,当我尝试运行此命令时,它会给出一个错误,指出 -print )
不是预期的,或者有时它只是在命令提示符下打印此命令。我想它在多个括号之间变得混乱。有什么线索我如何解决这个问题吗?
I am trying to write a small batch file for a task I do regularly. I have never used the for
before and this is the first time I am trying this. This is what I have come with so far:
for /f %i in ('ct find . -ver lbtype(%1) -print') do ct lsvt -g %i
Basically it tries find all the files with a given cleracase label and then display the version tree of those files. The problem is in the %1
. But when I try to run this sometime it gives me an error saying that -print )
was not expected or sometime else it just prints this command on the command prompt. I guess it is getting confused between multiple paranthesis. Any clues how o I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试引用您在
for
中执行的命令:这适用于我使用带有括号的参数的类似命令。
另外,(您可能已经知道),当您将命令放入 a 中时,您需要将
for
变量的'%'
字符加倍。批处理文件而不是在命令行运行它:Try quoting the command you're executing in the
for
:That worked for a similar command that I had that took args with parens.
Also, (as you're probably aware), you'll need to double-up on the
'%'
characters for thefor
variable when you put the command in a batch file instead of running it at the command line: