Sponsored Content
Full Discussion: Using color in scripts
Operating Systems Linux Ubuntu Using color in scripts Post 303033728 by drew77 on Wednesday 10th of April 2019 05:53:25 PM
Old 04-10-2019
I am using mate terminal.

I found another way which is easier to use and tput is part of the ncurses package and is supplied with most Linux distributions.

Code:
FILE="/usr/share/sounds/My_Sounds/Short_doorbell.wav"

if [ -f "$FILE" ];
then
     tput setaf 2; echo "File $FILE does exist."
else
     tput setaf 1; echo "File $FILE does NOT exist."
     
fi
tput sgr0    # Reset text format to the terminal's default


#Num  Colour    #define         R G B

#0    black     COLOR_BLACK     0,0,0
#1    red       COLOR_RED       1,0,0
#2    green     COLOR_GREEN     0,1,0
#3    yellow    COLOR_YELLOW    1,1,0
#4    blue      COLOR_BLUE      0,0,1
#5    magenta   COLOR_MAGENTA   1,0,1
#6    cyan      COLOR_CYAN      0,1,1
#7    white     COLOR_WHITE     1,1,1

These 3 Users Gave Thanks to drew77 For This Post:
 

2 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to change the background color in the init 3 mode(not line color)

Hello, I am using RHEL 6.1 on VMware I am searching for a way to change background color (not line by line color wich one can using tput command) basically changing the color of the whole screen to white instead of the default black and changing font color to black and alos would like to... (2 Replies)
Discussion started by: Dexobox
2 Replies

2. UNIX for Beginners Questions & Answers

Text color in Linux scripts via putty

hi Folks, Can anyone help with changing the color of the words in a linux shell script? I get how to change default background etc in putty, but for some reason the text in the script has different colors for different parts of the cript. Is there a way to have one color in a linux shell... (5 Replies)
Discussion started by: jonnyd
5 Replies
NCURSES_INIT_COLOR(3)							 1						     NCURSES_INIT_COLOR(3)

ncurses_init_color - Define a terminal color

SYNOPSIS
int ncurses_init_color (int $color, int $r, int $g, int $b) DESCRIPTION
Defines or redefines the given color. When this function is called, all occurrences of the given color on the screen, if any, immediately change to the new definition. Color capabilities must be supported by the terminal and initialized using ncurses_start_color(3) prior to calling this function. In addi- tion, the terminal must have color changing capabilities; use ncurses_can_change_color(3) to check for this. PARAMETERS
o $color - The identification number of the color to redefine. It may be one of the default color constants. o $r - A color value, between 0 and 1000, for the red component. o $g - A color value, between 0 and 1000, for the green component. o $b - A color value, between 0 and 1000, for the blue component. RETURN VALUES
Returns -1 if the function was successful, and 0 if ncurses or terminal color capabilities have not been initialized or the terminal does not have color changing capabilities. SEE ALSO
ncurses_color_content(3), ncurses_start_color(3). PHP Documentation Group NCURSES_INIT_COLOR(3)
All times are GMT -4. The time now is 11:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy