728x90
반응형
echo -e "\033[COLOR1;COLOR2m sample text\033[0m"
[ TEXT ATTRIBUTES ]
ANSI CODE Meaning
0 Normal Characters
1 Bold Characters
4 Underlined Characters
5 Blinking Characters
7 Reverse video Characters
[ COLORS ]
Bold off | color | Bold on | color |
---|---|---|---|
0;30 | Balck | 1;30 | Dark Gray |
0;31 | Red | 1;31 | Dark Red |
0;32 | Green | 1;32 | Dark Green |
0;33 | Brown | 1;33 | Yellow |
0;34 | Blue | 1;34 | Dark Blue |
0;35 | Magenta | 1;35 | Dark Magenta |
0;36 | Cyan | 1;30 | Dark Cyan |
0;37 | Light Gray | 1;30 | White |
Color | Foreground | Background |
---|---|---|
black | 30 | 40 |
red | 31 | 41 |
green | 32 | 42 |
yellow | 33 | 43 |
blue | 34 | 44 |
magenta | 35 | 45 |
cyan | 36 | 46 |
white | 37 | 47 |
$ echo -e '\E[47;34m'"\033[1mE\033[0m"
흰색배경에 파란색 글씨로 m이라고 출력됨
echo -e "\033[COLORm Sample text"
The "\033[" begins the escape sequence.You can also use "\e[" instead
of "\033[". COLOR specifies a foreground color, according to the table
above.The "m" terminates escape sequence, and text begins immediately
after that.
Note: With an echo, the -e option enables the escape sequences.You can
also use printf instead of echo.
printf "\e[COLORm sample text\n"
To print Green text
echo -e "\033[32m Hello World"
or
printf "\e[32m Hello World"
정상으로 돌아오려면
echo -e "\033[0m"
[ Some examples ]
Block background and white text
1 | echo -e "\033[40;37m Hello World\033[0m" |
Reverse video text attribute option interchanges fg and bg colors.
Bellow statement prints block on white
Bellow statement prints block on white
1 2 3 4 | echo -e "\033[40;37;7m Hello World\033[0m" echo -e "\033[33;44m Yellow text on blue background\033[0m" echo -e "\033[1;33;44m Bold yellow text on blue background\033[0m" echo -e "\033[1;4;33;44mBold yellow underlined text on blue background\033[0m" |
[ The "tput" command: ]
Other than echo there is a command called tput using which we
can control the way the output is displayed on the screen.But it is
less flexible than ANSI escape sequences.
[ SCRIPT SAMPLE ]
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/bash # This script echoes colors and codes echo -e "\n\033[4;31mLight Colors\033[0m \t\t\033[1;4;31mDark Colors\033[0m" echo -e "\e[0;30;47m Black \e[0m 0;30m \t\e[1;30;40m Dark Gray \e[0m 1;30m" echo -e "\e[0;31;47m Red \e[0m 0;31m \t\e[1;31;40m Dark Red \e[0m 1;31m" echo -e "\e[0;32;47m Green \e[0m 0;32m \t\e[1;32;40m Dark Green \e[0m 1;32m" echo -e "\e[0;33;47m Brown \e[0m 0;33m \t\e[1;33;40m Yellow \e[0m 1;33m" echo -e "\e[0;34;47m Blue \e[0m 0;34m \t\e[1;34;40m Dark Blue \e[0m 1;34m" echo -e "\e[0;35;47m Magenta \e[0m 0;35m \t\e[1;35;40m DarkMagenta\e[0m 1;35m" echo -e "\e[0;36;47m Cyan \e[0m 0;36m \t\e[1;36;40m Dark Cyan \e[0m 1;36m" echo -e "\e[0;37;47m LightGray\e[0m 0;37m \t\e[1;37;40m White \e[0m 1;37m" |
[ANSI 문자]
Dec | abbr | cmd | echo | Note | Dec | abbr | cmd | echo | Note | Dec | abbr | cmd | echo | Note |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | NUL | ^@ | x | 12 | FF | ^L | 24 | CAN | ^X | |||||
1 | SOH | ^A | 13 | CR | ^M | x | 줄바꿈 | 25 | EM | ^Y | ||||
2 | STX | ^B | 14 | SO | ^N | 26 | SUB | ^Z | x | |||||
3 | ETX | ^C | 15 | SI | ^O | 27 | ESC | ^[ | ||||||
4 | EOT | ^D | 16 | DLE | ^P | 28 | FS | ^\ | ||||||
5 | ENQ | ^E | 17 | DC1 | ^Q | 29 | GS | ^] | ||||||
6 | ACK | ^F | 18 | DC2 | ^R | 30 | RS | ^^ | ||||||
7 | BEL | ^G | 소리 | 19 | DC3 | ^S | 31 | US | ^_ | |||||
8 | BS | ^H | 지우기 | 20 | DC4 | ^T | 32 | SP | 공백 | 공백 | 공백 | |||
9 | HT | ^I | x | 탭 | 21 | NAK | ^U | 127 | DEL | ^? | ||||
10 | LF | ^J | x | 22 | SYN | ^V | ||||||||
11 | VT | ^K | 23 | ETB | ^W | |||||||||
* x 사용할 수 없거나 Null 값으로 처리됨. * ASCII Code 8 은 BackSpace 로 배치 파일에서 사용되면 의미 그대로 앞의 한 글자를 지웁니다. * 명령 프롬프트의 Echo 출력 결과는 Color F0 으로 설정한 후 캡쳐한 것입니다. |
TAG •
728x90
반응형
'UNIX&LINUX > 쉘스크립트' 카테고리의 다른 글
[Shell Script] 비교 표현식 gt lt ge le eq ne (0) | 2017.11.14 |
---|---|
expect를 이용한 자동화(3) - 원격 장비 passwd 변경 (0) | 2014.07.17 |
expect를 이용한 자동화(2) - scp (0) | 2014.07.17 |
expect를 이용한 자동화(1) - ssh (0) | 2014.07.17 |
쉘스크립트 컬러 넣는 법 (0) | 2014.07.14 |
grep 제외문자열 -v -Ev (0) | 2014.07.14 |
쉘 스크립트 연산자 (0) | 2014.07.14 |
쉘스크립트 기본 if문 (0) | 2014.07.14 |