shell script output with color font

shell script output various special effects

Output effect format control:
\033[0m close all properties \033[1m set highlight \033[4m underline \033[5m flash \033[7m inverse \033[8m blank \033[30m -- \033[ 37m set foreground color \033[40m -- \033[47m set background color  
  
  
  
  
  
  

Format control of cursor position, etc.:
\033[nA cursor up n lines  
\03[nB cursor down n lines  
\033[nC cursor right n lines  
\033[nD cursor left n lines  
\033[y;xH setting Cursor position  
\033[2J Clear screen  
\033[K Clear content from cursor to end of line  
\033[s Save cursor position  
\033[u Restore cursor position  
\033[?25l Hide cursor  

\33[?25h display cursor

Finish:
    Code Color/Action
  0 Reset Attributes to Default
  1 Set Bold
  2 Set Half Brightness (simulates color on a color monitor)
  4 Set underline (simulates color on a color monitor)
  5 Set Flash
  7 Set Inverted Image
  22 Set Normal Density
  24 Underline Off
  25 Flicker Off
  27 Invert Image Off
  30 Set Black Foreground
  31 Set Red Foreground
  32 Set Green Foreground
  33 Set Brown Foreground
  34 Set Blue Foreground
  35 Set Purple Foreground
  36 Set Cyan Foreground
  37 Set White Foreground
  38 Set underline
  on dart foreground color 39 Turn off underline on default foreground color
  40 Set black background
  41 Set red background
  42 Set green background
  43 Set brown background
  44 Set blue background
  45 Set purple background
  46 Set cyan background
  47 Set white background
  49 Set default black background
The special effects can be superimposed and need to be separated by ";", for example: flashing + underline + white background + black text is \033[5;4;47;30m flashing + underline + white background + black text is \033[0m
Here is a small example:

#!/bin/bash
#
#The following is the font output color and terminal format control
#Font color range: 30 - 37 
echo -e " \033[30m black words\033[0m " 
echo -e " \033[31m red words\033[0m " 
echo -e " \033[32m green words\033 [0m " 
echo -e " \033[33m yellow word \033[0m " 
echo -e " \033[34m blue word \033[0m " 
echo -e " \033[35m purple word \033[0m " 
echo -e " \033[36m sky blue characters\033[0m " 
echo -e " \033[37m white characters\033[0m "
#Word background color range:40 - 47 
echo -e " \033[40;37m White text on black background\033[0m " 
echo -e " \033[41;30m Black text on red background\033[0m " 
echo -e " \033[42;34m Blue text on green background\033[0m " 
echo -e " \033[43;34m Blue text on yellow background\033[0m " 
echo -e " \033[44;30m Black text on blue background\033[0m " 
echo -e " \033[45;30m black text on purple background\033[0m " 
echo -e " \033[46;30m black text on sky blue background\033[0m " 
echo -e " \033[47;34m blue text on white background\ 033[0m "

#Control option description
#\ 033 [0m Close all properties
#\ 033 [1m set high brightness
#\ 033 [4m underline
 echo -e " \033[4;31m underline red \033[0m "
#blink
echo -e " \033[5;34m The red letter is flashing\033[0m "
#reflection
echo -e " \033[8m blanks \033[0m "

#\ 033 [30m-\ 033 [37m set foreground color
#\ 033 [40m-\ 033 [47m set background color
#\ 033 [nA cursor up n lines
#\ 033 [nB cursor moves down n lines
 echo -e " \033[4A cursor moves up 4 lines \033[0m " 
#\ 033 [nC cursor moves right n lines
#\ 033 [nD cursor left n lines
#\ 033 [y;xH set cursor position
#\ 033 [2J clear screen
#\ 033 [K clear the content from the cursor to the end of the line
 echo -e " \033[K clear the content from the cursor to the end of the line \033[0m " 
#\ 033 [s save the cursor position
#\ 033 [u restore cursor position
#\ 033 [? 25 | hide cursor
#\ 033 [? 25h show cursor
 echo -e " \033[?25l hide cursor \033[0m " 
echo -e " \033[?25h show cursor \033[0m "

Reprinted: https://blog.csdn.net/andylauren/article/details/60873400

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324969906&siteId=291194637