[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理if else嵌套脚本报错

运行一直报错:The syntax of the command is incorrect.
哪位可以帮忙看看,谢谢!

------------------------------------------------------------------------------------
  1. @echo off
  2. @hostname>>"c:\temp\hostname.txt"
  3. set /p host=<c:\temp\hostname.txt
  4. if "%host:~7,5% lss 10031 (echo %user% is Com_PRD_PPC01)
  5. else if "%host:~7,5% lss 10061 (echo %user% is Com_PRD_PPC02)
  6. else if "%host:~7,5% lss 10091 (echo %user% is Com_PRD_PPC03)
  7. else if "%host:~7,5% lss 10121 (echo %user% is Com_PRD_PPC04)
  8. else if "%host:~7,5% lss 10151 (echo %user% is Com_PRD_PPC05)
  9. else if "%host:~7,5% lss 10181 (echo %user% is Com_PRD_PPC06)
  10. else if "%host:~7,5% lss 10211 (echo %user% is Com_PRD_PPC07)
  11. else if "%host:~7,5% lss 10241 (echo %user% is Com_PRD_PPC08)
  12. else if "%host:~7,5% lss 10271 (echo %user% is Com_PRD_PPC09)
  13. else if "%host:~7,5% lss 10301 (echo %user% is Com_PRD_PPC10)
  14. else if "%host:~7,5% lss 10331 (echo %user% is Com_PRD_PPC11)
  15. else if "%host:~7,5% lss 10361 (echo %user% is Com_PRD_PPC12)
  16. else if "%host:~7,5% lss 10391 (echo %user% is Com_PRD_PPC13)
  17. else if "%host:~7,5% lss 10421 (echo %user% is Com_PRD_PPC14)
  18. else if "%host:~7,5% lss 10451 (echo %user% is Com_PRD_PPC15)
  19. else if "%host:~7,5% lss 10481 (echo %user% is Com_PRD_PPC16)
  20. else if "%host:~7,5% lss 10511 (echo %user% is Com_PRD_PPC17)
  21. else if "%host:~7,5% lss 10541 (echo %user% is Com_PRD_PPC18)
  22. else if "%host:~7,5% lss 10571 (echo %user% is Com_PRD_PPC19)
  23. else if "%host:~7,5% lss 10601 (echo %user% is Com_PRD_PPC20)
  24. else if "%host:~7,5% lss 10631 (echo %user% is Com_PRD_PPC21)
  25. else if "%host:~7,5% lss 10661 (echo %user% is Com_PRD_PPC22)
  26. else if "%host:~7,5% lss 10691 (echo %user% is Com_PRD_PPC23)
  27. else if "%host:~7,5% lss 10721 (echo %user% is Com_PRD_PPC24)
  28. else if "%host:~7,5% lss 10751 (echo %user% is Com_PRD_PPC25)
  29. else if "%host:~7,5% lss 10781 (echo %user% is Com_PRD_PPC26)
  30. else (goto eof)
  31. copy c:\Script\Time\shortcut.lnk "C:\Users\%user%\Desktop\shortcut.lnk"
  32. pause&exit
复制代码

回复 1# conan52


   
ELSE 子句必须出现在同一行上的 IF 之后。例如:

    IF EXIST filename. (
        del filename.
    ) ELSE (
        echo filename. missing.
    )

TOP

回复 2# wujunkai


    是要if回车,另起一行吗?好像还是不行啊。

TOP

本帖最后由 went 于 2020-4-9 15:30 编辑
  1. @echo off
  2. for /f "delims=" %%i in ('hostname') do set "host=%%i"
  3. echo %host%
  4. if "%host:~7,5%" lss "10031" (echo %user% is Com_PRD_PPC01 & goto :done)
  5. if "%host:~7,5%" lss "10061" (echo %user% is Com_PRD_PPC02 & goto :done)
  6. if "%host:~7,5%" lss "10091" (echo %user% is Com_PRD_PPC03 & goto :done)
  7. if "%host:~7,5%" lss "10121" (echo %user% is Com_PRD_PPC04 & goto :done)
  8. if "%host:~7,5%" lss "10151" (echo %user% is Com_PRD_PPC05 & goto :done)
  9. if "%host:~7,5%" lss "10181" (echo %user% is Com_PRD_PPC06 & goto :done)
  10. if "%host:~7,5%" lss "10211" (echo %user% is Com_PRD_PPC07 & goto :done)
  11. if "%host:~7,5%" lss "10241" (echo %user% is Com_PRD_PPC08 & goto :done)
  12. if "%host:~7,5%" lss "10271" (echo %user% is Com_PRD_PPC09 & goto :done)
  13. if "%host:~7,5%" lss "10301" (echo %user% is Com_PRD_PPC10 & goto :done)
  14. if "%host:~7,5%" lss "10331" (echo %user% is Com_PRD_PPC11 & goto :done)
  15. if "%host:~7,5%" lss "10361" (echo %user% is Com_PRD_PPC12 & goto :done)
  16. if "%host:~7,5%" lss "10391" (echo %user% is Com_PRD_PPC13 & goto :done)
  17. if "%host:~7,5%" lss "10421" (echo %user% is Com_PRD_PPC14 & goto :done)
  18. if "%host:~7,5%" lss "10451" (echo %user% is Com_PRD_PPC15 & goto :done)
  19. if "%host:~7,5%" lss "10481" (echo %user% is Com_PRD_PPC16 & goto :done)
  20. if "%host:~7,5%" lss "10511" (echo %user% is Com_PRD_PPC17 & goto :done)
  21. if "%host:~7,5%" lss "10541" (echo %user% is Com_PRD_PPC18 & goto :done)
  22. if "%host:~7,5%" lss "10571" (echo %user% is Com_PRD_PPC19 & goto :done)
  23. if "%host:~7,5%" lss "10601" (echo %user% is Com_PRD_PPC20 & goto :done)
  24. if "%host:~7,5%" lss "10631" (echo %user% is Com_PRD_PPC21 & goto :done)
  25. if "%host:~7,5%" lss "10661" (echo %user% is Com_PRD_PPC22 & goto :done)
  26. if "%host:~7,5%" lss "10691" (echo %user% is Com_PRD_PPC23 & goto :done)
  27. if "%host:~7,5%" lss "10721" (echo %user% is Com_PRD_PPC24 & goto :done)
  28. if "%host:~7,5%" lss "10751" (echo %user% is Com_PRD_PPC25 & goto :done)
  29. if "%host:~7,5%" lss "10781" (echo %user% is Com_PRD_PPC26 & goto :done)
  30. pause&exit
  31. :done
  32. copy "c:\Script\Time\shortcut.lnk" "C:\Users\%user%\Desktop\shortcut.lnk"
  33. pause&exit
复制代码

TOP

回复 4# went


    还是报错。

TOP

回复 5# conan52


    报什么错

TOP

一样的错误

TOP

回复 6# went


    The syntax of the command is incorrect.

TOP

回复 8# conan52


    hostname显示什么,再试试4楼

TOP

回复 9# went


    一样,错误信息,之前能显示出正确的本机主机名。

TOP

回复 10# conan52


    你测试的主机名是什么

TOP

  1. if "%host:~7,5%" lss "10031" (echo %user% is Com_PRD_PPC01&&goto done)
复制代码
把4楼的修改 参照这一句。我的电脑 echo %user% 没有这个。
目的,学习批处理

TOP

返回列表