bash正则expression式命令相当于Windows cmd脚本

什么是这个bash命令的等价物:

[[ $(uname) =~ NT-6.3 ]] && set_win81 

Windows CMD脚本?

我正在跳跃使用像这样的东西:

 if (ver | findstr /C:"Microsoft Windows [Version 6.3") ( goto :set_win81 ) 

像这样的东西就足够了。

 ver | findstr /i /c:"Version 6.3" >nul && goto :set_win81 

下面是我为了这个任务而松了一口气的代码:

 @echo off set "windows=" VER | find " 4.1." > nul && set windows=W98 VER | find " 4.0." > nul && set windows=NT VER | find " 5.0." > nul && set windows=W2K VER | find " 5.1." > nul && set windows=XP VER | find " 5.2." > nul && set windows=XP 64-Bit or server 2003 or server 2003 R2 VER | find " 6.0." > nul && set windows=Vista or server 2008 VER | find " 6.1." > nul && set windows=Win7 or server 2008 R2 VER | find " 6.2." > nul && set windows=Windows 8 VER | find " 6.3." > nul && set windows=server 2012 R2 or Windows 8.1 if defined windows ( echo %windows% ) else ( echo unknown operating system ) pause 

作为解析ver输出的替代方法,您可以使用注册表:

 setlocal set reg_info=reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion for /f "skip=2 tokens=3" %%l in ('%reg_info%') do set win_ver=%%l if "%win_ver%" equ "6.2" goto :set_win80 if "%win_ver%" equ "6.3" goto :set_win81 REM etc etc 

关键是你可以使用for /f循环和几个设置来解析多行,多列的数据,比如reg query的输出。

 @echo off setlocal :: Get windows Version numbers set ver="" set con="Microsoft Windows Version 6.3" for /f "tokens=2 delims=[]" %%G in ('ver') do set ver=%%G echo found version %ver% if %%ver EQU %%con ( goto set_win81) echo NO win81 exit/B :set_win81 echo win81 exit/B