Detailed Video :
• Unix Basics | Changing...
Changing Font Color
ANSI escape sequences are a standard for in-band signaling to control many terminal operations like,
cursor location, color, font styling etc.
Output color of Echo in Linux can be achieved using the respective ANSI escape codes.
This has to be prefixed by an argument called \033[, followed by the code for the color that needs to be specified.
Enable interpretation of backslash escapes.
All ANSI escape codes start with the Escape character( \033 in octal format).
\033[command
m is the last character of the escape sequence.
e.g.
echo -e "\033[0;32m Displaying Green Colored Text \033[0;0m"
echo -e is to take escape sequence.
Color Codes Text Styles Codes
Black 30 Simple text 0
Red 31 Bold text 1
Green 32 Low intensity text 2
Brown/Orange 33 Underline text 4
Blue 34 Blinking text 5
Purple 35 Invisible text 8
Cyan 36 Strikethrough text 9
Light Gray 37
echo -e "\033[38;5;205m Displaying Yellow Colored Text "
You can use these ANSI escape codes:
FG BG Name
Low intensity
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Magenta
36 46 Cyan
37 47 White
High intensity
90 100 Bright Black (Gray)
91 101 Bright Red
92 102 Bright Green
93 103 Bright Yellow
94 104 Bright Blue
95 105 BrightMagenta
96 106 Bright Cyan
97 107 Bright White
e.g.
demo_ansi_color.sh
#!/bin/bash
echo -e "\033[0;31m Displaying red Colored Text \033[0;0m"
echo -e "\033[38;5;1m Displaying red Colored Text \033[0;0m"
echo -e "\033[0;41m Displaying red Colored Text in background \033[0;0m"
echo -e "\033[48;5;1m Displaying red Colored Text in background \033[0;0m"
echo -e "\033[0;32m Displaying Green Colored Text \033[0;0m"
echo -e "\033[0;42m Displaying Green Colored Text in background \033[0;0m"
echo -e "\033[0;35m Displaying Magenta Colored Text \033[0;0m"
echo -e "\033[0;36m Displaying Cyan Colored Text \033[0;0m"
echo -e "\033[4;31m Displaying underlined Text \033[0;0m"
echo -e "\033[5;31m Displaying blinking Text \033[0;0m"
echo -e "\033[9;31m Displaying strike through Text \033[0;0m"
echo -e "\033[1;33m Displaying bold yellow Text \033[0;0m"
echo -e "\033[2;33m Displaying low intensity yellow Text \033[0;0m"
printf "\033[0;31m Displaying red Colored Text using printf \033[0;0m"
printf "
"
echo -e "\033[0;0m Used to reset special formatting"
GREEN='\033[0;32m'
RESET='\033[0;0m'
echo -e " ${GREEN}Green color text${RESET}"
#unixbasics #font #color #unix #unixtutorial #fontcolor #unix #unixtutorial #ANSI #ANSI #escape #codes #learning #coding #programming
Негізгі бет Unix Basics | Changing font color | How to change font color? | ANSI escape codes |
Пікірлер: 1