[英]Why does execution in shell give different result that execution in batch script?
I'd like to list all .csv files in a directory and its subdirectories.我想列出目录及其子目录中的所有 .csv 文件。 It works nicely when I run this in the cmd terminal:
当我在 cmd 终端中运行它时,它运行良好:
for /f %a in ('dir /b /s *.csv') do (echo %a)
When I put the same line of code into an (otherwise empty) text file (.cmd) and run that .cmd file, it outputs a blank line, but does not list any files.当我将同一行代码放入(否则为空)文本文件 (.cmd) 并运行该 .cmd 文件时,它输出一个空行,但不列出任何文件。
Why does it make a difference whether I put the commands into a script or enter them directly (in one go) in the terminal?为什么将命令放入脚本中或直接(一次性)在终端中输入命令会有所不同?
Thinking it might be a delayed expansion issue, I also tried for /f %a in ('dir /b /s *.csv') do (echo !a!)
, but this doesn't list the files either.认为这可能是延迟扩展问题,我还尝试
for /f %a in ('dir /b /s *.csv') do (echo !a!)
,但这也没有列出文件。
Any ideas?有任何想法吗?
将批处理文件中的百分比符号加倍!
for /f %%a in ('dir /b /s *.csv') do (echo %%a)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.