发现win8.1(PowerShell 4.0)与 win7(PowerShell 2.0)在脚本块中定义变量有区别
脚本块中的变量作用域原本应该是Local性质的,但win7把它当作Global传递,混乱了。
以下代码win7、win8.1测试通过(第1列/10;第2列/20;第3列/30;......):- @echo off
- set "r='\d+\.?\d*[Ee][-+]\d{3}'"
- set "s=[IO.File]::ReadAllText($_,[Text.Encoding]::Default)"
- md new\ 2>nul
- PowerShell -c "dir *.txt|%%{[regex]::Replace(%s%,\"[^^`r`n]+\",{param($a,$global:i=0);[regex]::Replace($a.Value,%r%,{param($b);($b.Value/++$global:i/10).ToString('e8')})})>('new\'+$_.Name)}"
- pause
复制代码
|