标题: [文本处理] 批处理if else嵌套脚本报错 [打印本页]
作者: conan52 时间: 2020-4-9 14:07 标题: 批处理if else嵌套脚本报错
运行一直报错:The syntax of the command is incorrect.
哪位可以帮忙看看,谢谢!
------------------------------------------------------------------------------------- @echo off
-
- @hostname>>"c:\temp\hostname.txt"
-
- set /p host=<c:\temp\hostname.txt
-
- if "%host:~7,5% lss 10031 (echo %user% is Com_PRD_PPC01)
- else if "%host:~7,5% lss 10061 (echo %user% is Com_PRD_PPC02)
- else if "%host:~7,5% lss 10091 (echo %user% is Com_PRD_PPC03)
- else if "%host:~7,5% lss 10121 (echo %user% is Com_PRD_PPC04)
- else if "%host:~7,5% lss 10151 (echo %user% is Com_PRD_PPC05)
- else if "%host:~7,5% lss 10181 (echo %user% is Com_PRD_PPC06)
- else if "%host:~7,5% lss 10211 (echo %user% is Com_PRD_PPC07)
- else if "%host:~7,5% lss 10241 (echo %user% is Com_PRD_PPC08)
- else if "%host:~7,5% lss 10271 (echo %user% is Com_PRD_PPC09)
- else if "%host:~7,5% lss 10301 (echo %user% is Com_PRD_PPC10)
- else if "%host:~7,5% lss 10331 (echo %user% is Com_PRD_PPC11)
- else if "%host:~7,5% lss 10361 (echo %user% is Com_PRD_PPC12)
- else if "%host:~7,5% lss 10391 (echo %user% is Com_PRD_PPC13)
- else if "%host:~7,5% lss 10421 (echo %user% is Com_PRD_PPC14)
- else if "%host:~7,5% lss 10451 (echo %user% is Com_PRD_PPC15)
- else if "%host:~7,5% lss 10481 (echo %user% is Com_PRD_PPC16)
- else if "%host:~7,5% lss 10511 (echo %user% is Com_PRD_PPC17)
- else if "%host:~7,5% lss 10541 (echo %user% is Com_PRD_PPC18)
- else if "%host:~7,5% lss 10571 (echo %user% is Com_PRD_PPC19)
- else if "%host:~7,5% lss 10601 (echo %user% is Com_PRD_PPC20)
- else if "%host:~7,5% lss 10631 (echo %user% is Com_PRD_PPC21)
- else if "%host:~7,5% lss 10661 (echo %user% is Com_PRD_PPC22)
- else if "%host:~7,5% lss 10691 (echo %user% is Com_PRD_PPC23)
- else if "%host:~7,5% lss 10721 (echo %user% is Com_PRD_PPC24)
- else if "%host:~7,5% lss 10751 (echo %user% is Com_PRD_PPC25)
- else if "%host:~7,5% lss 10781 (echo %user% is Com_PRD_PPC26)
- else (goto eof)
-
- copy c:\Script\Time\shortcut.lnk "C:\Users\%user%\Desktop\shortcut.lnk"
-
- pause&exit
复制代码
作者: wujunkai 时间: 2020-4-9 14:09
回复 1# conan52
ELSE 子句必须出现在同一行上的 IF 之后。例如:
IF EXIST filename. (
del filename.
) ELSE (
echo filename. missing.
)
作者: conan52 时间: 2020-4-9 14:21
回复 2# wujunkai
是要if回车,另起一行吗?好像还是不行啊。
作者: went 时间: 2020-4-9 14:40
本帖最后由 went 于 2020-4-9 15:30 编辑
- @echo off
- for /f "delims=" %%i in ('hostname') do set "host=%%i"
- echo %host%
- if "%host:~7,5%" lss "10031" (echo %user% is Com_PRD_PPC01 & goto :done)
- if "%host:~7,5%" lss "10061" (echo %user% is Com_PRD_PPC02 & goto :done)
- if "%host:~7,5%" lss "10091" (echo %user% is Com_PRD_PPC03 & goto :done)
- if "%host:~7,5%" lss "10121" (echo %user% is Com_PRD_PPC04 & goto :done)
- if "%host:~7,5%" lss "10151" (echo %user% is Com_PRD_PPC05 & goto :done)
- if "%host:~7,5%" lss "10181" (echo %user% is Com_PRD_PPC06 & goto :done)
- if "%host:~7,5%" lss "10211" (echo %user% is Com_PRD_PPC07 & goto :done)
- if "%host:~7,5%" lss "10241" (echo %user% is Com_PRD_PPC08 & goto :done)
- if "%host:~7,5%" lss "10271" (echo %user% is Com_PRD_PPC09 & goto :done)
- if "%host:~7,5%" lss "10301" (echo %user% is Com_PRD_PPC10 & goto :done)
- if "%host:~7,5%" lss "10331" (echo %user% is Com_PRD_PPC11 & goto :done)
- if "%host:~7,5%" lss "10361" (echo %user% is Com_PRD_PPC12 & goto :done)
- if "%host:~7,5%" lss "10391" (echo %user% is Com_PRD_PPC13 & goto :done)
- if "%host:~7,5%" lss "10421" (echo %user% is Com_PRD_PPC14 & goto :done)
- if "%host:~7,5%" lss "10451" (echo %user% is Com_PRD_PPC15 & goto :done)
- if "%host:~7,5%" lss "10481" (echo %user% is Com_PRD_PPC16 & goto :done)
- if "%host:~7,5%" lss "10511" (echo %user% is Com_PRD_PPC17 & goto :done)
- if "%host:~7,5%" lss "10541" (echo %user% is Com_PRD_PPC18 & goto :done)
- if "%host:~7,5%" lss "10571" (echo %user% is Com_PRD_PPC19 & goto :done)
- if "%host:~7,5%" lss "10601" (echo %user% is Com_PRD_PPC20 & goto :done)
- if "%host:~7,5%" lss "10631" (echo %user% is Com_PRD_PPC21 & goto :done)
- if "%host:~7,5%" lss "10661" (echo %user% is Com_PRD_PPC22 & goto :done)
- if "%host:~7,5%" lss "10691" (echo %user% is Com_PRD_PPC23 & goto :done)
- if "%host:~7,5%" lss "10721" (echo %user% is Com_PRD_PPC24 & goto :done)
- if "%host:~7,5%" lss "10751" (echo %user% is Com_PRD_PPC25 & goto :done)
- if "%host:~7,5%" lss "10781" (echo %user% is Com_PRD_PPC26 & goto :done)
- pause&exit
- :done
- copy "c:\Script\Time\shortcut.lnk" "C:\Users\%user%\Desktop\shortcut.lnk"
- pause&exit
复制代码
作者: conan52 时间: 2020-4-9 14:52
回复 4# went
还是报错。
作者: went 时间: 2020-4-9 15:06
回复 5# conan52
报什么错
作者: conan52 时间: 2020-4-9 15:14
一样的错误
作者: conan52 时间: 2020-4-9 15:23
回复 6# went
The syntax of the command is incorrect.
作者: went 时间: 2020-4-9 15:31
回复 8# conan52
hostname显示什么,再试试4楼
作者: conan52 时间: 2020-4-9 16:14
回复 9# went
一样,错误信息,之前能显示出正确的本机主机名。
作者: went 时间: 2020-4-9 16:29
回复 10# conan52
你测试的主机名是什么
作者: hlzj88 时间: 2020-4-9 21:05
- if "%host:~7,5%" lss "10031" (echo %user% is Com_PRD_PPC01&&goto done)
复制代码
把4楼的修改 参照这一句。我的电脑 echo %user% 没有这个。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |