Note: I reworked the question to clarify the issues. This is a trivial question that can be answered in several parts because the question has several attributes.
Unfortunately, the question may be reworked when the person asking the question apprehends (knows) some parts of the answer as well as the structure of the question.
Therefore, the question is presented from a different point of view than the original one.
How to change the color setting¹ of the Linux console, using a shell utility? How to change the color setting¹ of a terminal emulator, using a shell utility?
Originally, I wanted to change the background color of the Linux console during the execution of a shell script. The following proposition works as I wanted.
#!/bin/sh
# set the background color of the terminal
tput setab 6
clear
printf "%s\n" 'background: cyan'
# do some tasks
cd /usr/src/initramfs
pwd
ls -l
# the background of the shell output is cyan
Nonetheless, someone may encounter several glitches (or difficulties).
For instance, if the screen is not cleared, the background color is only applied to the text output, during a shell script execution. If the command tput setab 6
is submitted with the command line and the screen is not cleared, the background color is only applied to a small portion of the output text. If the command tput setab 6
is submitted on the command line and the screen is cleared, the background color is applied to the full screen but only persists until another command is submitted. [...]
¹ background color
console
do you mean `tty? – Arkadiusz Drabczyk Oct 10 '18 at 15:28