본문으로 건너뛰기

ShellScript Text color

ANSI escape code


  • \033: Escape(ESC)
  • \033[: Control Sequence Introducer(CSI)
    • \033[<parameter>[;<parameter>]m: Select Graphic Rendition(SGR)
      • <parameter>
        • 0: Reset or Normal
        • 1: Bold
      • Ex) \033[1;31m: Bold Red
RESET="\033[0m"
BOLD="\033[1m"

BLACK="\033[30m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"
WHITE="\033[37m"

printf "${RED}${BOLD}red${RESET}, ${YELLOW}yellow${RESET}\n"

tput

tput setab [1-7] # Set the background colour using ANSI escape
tput setaf [1-7] # Set the foreground colour using ANSI escape
NumColourdefineR,G,B
0blackCOLOR_BLACK0,0,0
1redCOLOR_RED1,0,0
2greenCOLOR_GREEN0,1,0
3yellowCOLOR_YELLOW1,1,0
4blueCOLOR_BLUE0,0,1
5magentaCOLOR_MAGENTA1,0,1
6cyanCOLOR_CYAN0,1,1
7whiteCOLOR_WHITE1,1,1
tput bold    # Select bold mode
tput dim # Select dim (half-bright) mode
tput smul # Enable underline mode
tput rmul # Disable underline mode
tput sgr0    # Reset text format to the terminal's default
tput bel # Play a bell
tput clear # Clear screen and move the cursor to 0,0
RESET=$(tput sgr0)
BOLD=$(tput bold)

BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)

printf "${RED}${BOLD}red${RESET}, ${YELLOW}yellow${RESET}\n"