如何制作这个批处理文件颜色选择器?

时间:2017-07-18 09:14:23

标签: batch-file cmd

@echo off
echo.
echo (backgroundColor_textColor)
echo set color (Blue_White or Red_White)
echo.
set COLOR=
set /p COLOR = choose color from the color given: 
if "%COLOR%"=="blue_white" goto bw
if "%COLOR%"=="blue white" goto bw
if "%COLOR%"=="Blue_White" goto bw
if "%COLOR%"=="Blue White" goto bw
if "%COLOR%"=="BW" goto bw
if "%COLOR%"=="bw" goto bw
if "%COLOR%"=="red_white" goto rw
if "%COLOR%"=="red white" goto rw
if "%COLOR%"=="Red_White" goto rw
if "%COLOR%"=="Red White" goto rw
if "%COLOR%"=="RW" goto rw
if "%COLOR%"=="rw" goto rw

:bw
color 1f
goto start

:rw
color 4f

:start
pause
echo.
pause

1 个答案:

答案 0 :(得分:1)

正如评论中提到的那样,您的问题是set命令中的空格。它应该是这样的:

set /p COLOR=choose color from the color given:

以下是您的脚本的“工作”版本:

@echo off
echo.
echo (backgroundColor_textColor)
echo set color (Blue_White or Red_White)
echo.
set COLOR=
set /p COLOR=choose color from the color given:
if "%COLOR%"=="blue_white" goto bw
if "%COLOR%"=="blue white" goto bw
if "%COLOR%"=="Blue_White" goto bw
if "%COLOR%"=="Blue White" goto bw
if "%COLOR%"=="BW" goto bw
if "%COLOR%"=="bw" goto bw
if "%COLOR%"=="red_white" goto rw
if "%COLOR%"=="red white" goto rw
if "%COLOR%"=="Red_White" goto rw
if "%COLOR%"=="Red White" goto rw
if "%COLOR%"=="RW" goto rw
if "%COLOR%"=="rw" goto rw

:bw
color 1f
goto start

:rw
color 4f

:start
pause
echo.
pause