This is the third epidose of a small series.
Description:
The days of monochrome green-on-black screens are over, in a remote shell terminal you can have something fancier!
BAD:
GOOD:
Define a series of variables as shortcuts for color escape codes, there are plenty of examples on internet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
colblk='\033[0;30m' # Black - Regular colred='\033[0;31m' # Red colgrn='\033[0;32m' # Green colylw='\033[0;33m' # Yellow colblu='\033[0;34m' # Blue colpur='\033[0;35m' # Purple colcyn='\033[0;36m' # Cyan colwht='\033[0;37m' # White colbblk='\033[1;30m' # Black - Bold colbred='\033[1;31m' # Red colbgrn='\033[1;32m' # Green colbylw='\033[1;33m' # Yellow colbblu='\033[1;34m' # Blue colbpur='\033[1;35m' # Purple colbcyn='\033[1;36m' # Cyan colbwht='\033[1;37m' # White colublk='\033[4;30m' # Black - Underline colured='\033[4;31m' # Red colugrn='\033[4;32m' # Green coluylw='\033[4;33m' # Yellow colublu='\033[4;34m' # Blue colupur='\033[4;35m' # Purple colucyn='\033[4;36m' # Cyan coluwht='\033[4;37m' # White colbgblk='\033[40m' # Black - Background colbgred='\033[41m' # Red colbggrn='\033[42m' # Green colbgylw='\033[43m' # Yellow colbgblu='\033[44m' # Blue colbgpur='\033[45m' # Purple colbgcyn='\033[46m' # Cyan colbgwht='\033[47m' # White colrst='\033[0m' # Text Reset |
Use them whenever you need to highlight the output of a script, and eventually integrate them in a smart prompt (like the one I’ve blogged about sometimes ago).
The echo builtin command requires -e in order to make the colours work. When reading files, cat works, less requires -r. vi may work with some hacking, but it’s not worth to spend too much time, IMHO.
The following two tabs change content below.
Latest posts by Ludovico (see all)
- New views in Oracle Data Guard 23c - January 3, 2024
- New in Data Guard 21c and 23c: Automatic preparation of the primary - December 22, 2023
- Does FLASHBACK QUERY work across incarnations or after a Data Guard failover? - December 13, 2023
Pingback: Bash tips & tricks [ep. 3]: Colour your terminal! - Ludovico Caldara - Blogs - triBLOG