Exit Status

The tput command provides exit status to indicate the success or failure of its execution. Here are the exit status codes commonly used:

  • 0: Indicates successful execution without any errors.
  • 1: Indicates a general error or failure during execution.
  • 2: Indicates invalid or unsupported capability or argument provided to tput.

How to Change the Output Color of Echo in Linux

When working with a computer, some users may encounter a situation where they need to output text in a different color. The colors we are familiar with by now will have been worked out for our particular machine and thus can be replaced easily if needed. Echo is a Linux command that can be used to change the output color of the text. Any text entered using echo is displayed in the new color before being output. The input method for this feature varies: bash, zsh, and python (as well as other shell extensions) will provide option -E, which disables it.  There are several ways to change foreground and background colors in Linux. Some examples showing how to use echo are included on this page.

Similar Reads

What is tput? How does it work?

tput is a command-line utility in Unix-like operating systems that allows users to interact with the terminal’s capabilities, such as cursor movement, text colors, and formatting. It works by sending terminal control sequences to manipulate terminal settings and appearance....

Reading Terminal Attributes

Reading terminal attributes involves retrieving information about the terminal settings, such as their size, supported features, and characteristics. This can be done using various methods, including terminal control codes, environment variables, or terminal query commands....

Change the Output Color of Echo in Linux

To change the color of the output using echo, users must first know the syntax of the command. First, let’s look at a sample command using no arguments to show the default color. The input color is blue, so the output should be green. Generally, the color of the commands follows the terminal’s color combination. In the below example, the commands and the Output are displayed in white color....

ANSI Codes

Changing the Output color of Echo in Linux can be achieved using the respective ANSI escape codes. “00” means echo -n; This is used as an output to the console, but will not work for a specific channel or voice you want to send your data with. In this example, we use 00:1c, which indicates that an important message should be sent directly into our mail server’s outgoing queue. If it didn’t receive any response from us after 20 seconds due to the long delay, then there may be something wrong here. The ANSI for various commonly used colors can be seen below....

Add color to the output of printf

We can also use the same to color the printf output...

Change color with the help of the Tput command

The command tput is used to change the text on the screen. It can be used to change the foreground and background colors. In addition, you can use the tput command to change the line wrapping, cursor position, and even text attributes like bold and underline. Tput commands are very useful for making a computer’s display look pretty....

Change the Foreground and Background Color in Bash

The Bash shell is the default shell for all new Linux, UNIX, and Mac OS X systems. This makes it one of the most popular shells in use today. The Bash shell is also very powerful; it offers an extensive range of options and functionality. Including a graphical user interface, the Bash shell is one of the most versatile in existence....

Using the Escape Sequence in Bash

The Escape Sequence in Bash can also be used to color text in bash. “Bash: colour” prints the resulting newlines with an ‘e’ character, which matches any of the following colors available from ASCII C and/or NCSU format numbers. This will change all other characters besides e into a blank line or otherwise leave them unchanged. It cannot match another shell variable that does not appear within its range as defined by this example script string: ${color:#0080ff} These values are interpreted using local special values for some terminals; they may differ slightly depending on your environment....

Syntax of tput

The tput command is used to interact with terminal capabilities, allowing you to perform various actions such as cursor movement, color manipulation, and text formatting. Its syntax is as follows:...

Exit Status

The tput command provides exit status to indicate the success or failure of its execution. Here are the exit status codes commonly used:...

Change the Output Color of Echo in Linux – FAQs

What is Linux tput?...