GOTO命令和附属标签有问题。
事实:从一个文件夹(他们是日志错误)的一堆文件,我需要打开它们,并检查它们是否包含特定的string。 如果是,则从文件名中删除一些字符(最后出现“_”后的所有字符,包括它自己)并执行其他操作。
为了切断字符我使用GOTO命令循环的方式,因为我发现它在这里描述: http : //www.robvanderwoude.com/battech_while_loops.PHP
脚本是:
命令解释
批量程序来检查过程是否存在
在同一个shell(bash)中运行脚本
我可以用命令行上的Windows行结尾来replaceUnix行尾吗?
如何使“du”命令运行而不输出所有目录,如安静模式?
@echo off setlocal EnableDelayedExpansion cls for %%X in (D:e-puboutBoxlogs*.*) do ( for /F "tokens=7" %%s in (%%X) do ( if /i "%%s"=="<ml>" ( SET fisier=%%~nX SET cond=!fisier:~-1! SET fisier=!fisier:~0,-1! :loopStart rem condition to break the loop if !cond!==_ goto loopEnd SET cond=!fisier:~-1! SET fisier=!fisier:~0,-1! goto loopStart :loopEnd rem here it should be out of a loop rem other stuff to do with var !fisier! rem the following line is not executed because of the label loopEnd echo !fisier! ) ) ) pause
该脚本没有运行,因为标签loopEnd后有一个空行? 如果我在该标签后面写任何指令,它们将被执行,但是第一个for语句的其余迭代不会被执行(日志错误文件夹包含更多的一个文件)
有人可以提供帮助吗?
Unix命令“uniq”&“sort”
sed命令在多行search后插入多行string
编写rakefile在Windows中运行命令的最佳方法是什么?
你有两个问题。
一个问题是goto打破了一个for循环。 另一方面,括号中的标签相当困难。
即使goto的标签位于同一个块中,goto也会始终中断,而且所有嵌套的循环都会被中断,并且跳转后立即丢失for变量。
在括号里面是“两行”的! 我用标签进行了实验,这里有一些括号的结果。
当出现标签时,下一行必须采用正确的“辅助”格式。
这就是为什么失败。
( :this label fails with a Syntax error ) ( :this works :because this line is a "legal" secondary line ) ( :: The remark style :: fails,because it's not "legal" to use a double colon,because it's not a legal path (in the most cases) ) ( :and Now I got courIoUs & echo This will not echo'd :but & echo You can see this ! )
对于第二行,批解析器的一些步骤将被跳过。
@不起作用, @echo.bat @echo Hello试图启动一个名为@echo.bat的文件。
括号的分割失败,就像echo( hello 。
将标签作为文件名称进行处理:echo只有在:echo才会检查:echo是有效的文件名,然后跳过该部分。
::hello在驱动器:: ::hello搜索。
出于测试目的,可以使用subst :: c:temp创建drive :: 。
由于标签在第二行被简单忽略,所以&符号和管道都可以工作,但::上的文件必须存在。
( echo @echo This is %~f0 ) > %TEMP%testLabel.bat REM create Drive :: subst :: %temp% ( :Label ::testLabel.bat The bat will not be executed | echo But this ) subst /D ::
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。