How to echo with different colors in the Windows command line

前端 未结 23 1492
野性不改
野性不改 2020-11-22 08:55

I know that the color bf command sets the colors of the whole command line window but I wanted to to print one single line in a different color.

23条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 09:42

    Windows 10 - TH2 and above:

    (a.k.a. Version 1511, build 10586, release 2015-11-10)

    At Command Prompt:

    echo ^[[32m HI ^[[0m
    

    Using the actual keys:   echo Ctrl+[[32m HI Ctrl+[[0mEnter

    You should see a green "HI" below it.

    Code numbers can be found here:

    • https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

    Notepad:

    To save this into notepad, you can type ESC into it using: Alt+027 with the numpad, then the [32m part. Another trick when I was on a laptop, redirect the line above into a file to get started, then cut and paste:

    echo echo ^[[32m HI ^[[0m >> batch_file.cmd
    

提交回复
热议问题