Introduction
The echo command outputs a given string to the commonplace output pipe, sometimes pointing to the terminal. Though the usual output pipe can level to different interfaces – the echo command is often used to print and show messages within the terminal. By default, the textual content of the displayed messaged inherits the colour of different textual content within the terminal (which is customizable in and of itself). Nonetheless – there are a number of methods you may alter the output coloration of echo – each for particular person strings and for whole messages.
On this quick information, we’ll check out how one can change the output coloration of
echoin Linux-based programs, utilizing ANSI escape codes,tputand how one can make this course of much less verbose in Bash scripts.
Change Output Shade with ANSI Escape Codes
The simplest method to change the colour is thru ANSI escape sequences/codes. All ANSI escape codes begin with the Escape character, which may be represented in varied codecs – 27 in decimal, x1B in hexadecimal, because the management key ^[, or
