bat

bat文件注意事项

Posted by Darren Blog on September 11, 2024

bat文件注意事项:

  • set value中等号前后不能有空格
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    :INFO
    echo ******************Setup for Project******************
    echo [1] Clone config files:
    echo Run CMD: conan config install ssh://%USERNAME%@eps-sw-gerrit-ssh.volvocars.net:29418/conan/cfg --type git
    echo [2] Install dependency and Generte project script:
    echo Run CMD: conan install .. --update --build=missing
    echo [3] Build Project and Generte C Codes:
    echo Run CMD: conan build ..
    echo [INFO]Current Path: %cd% 
    set /p sel=Please input number:
    
  • if else 后括号
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    if %sel% == 1 (
    REM echo enter %sel%
    goto CLONE_CONFIG
    ) else if %sel% == 2 (
    REM echo enter %sel%
    goto CONAN_INSTALL
    ) else if %sel% == 3 (
    REM echo enter %sel%
    goto CONAN_BUILD
    ) else (
    echo [ERROR]Not Supported!
    goto INFO
    )
    
  • 判断路径存在
    1
    2
    3
    4
    5
    6
    
    set "build_folder=%cd%\build"
    if not exist %build_folder%\%NUL% (
    mkdir %build_folder%
    ) else (
    echo "exist."
    )
    
  • 变量延迟
    1
    
    setlocal enabledelayedexpansion 
    
  • pending
  • pending
  • pending