LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   change the font color (https://www.linuxquestions.org/questions/linux-general-1/change-the-font-color-351577/)

Drunkalot 08-09-2005 02:44 PM

change the font color
 
I'm making a script for automating the backup here in the enterprize I work, and I output the log to a file with the echo command...

I need to know how can I change the color of the font, so that when success I write in green and when fail I write in red...

Is that a way to do that???


thx..

secesh 08-09-2005 05:18 PM

first hit on google:

http://www.linuxvoodoo.com/resources...olorizing.html

jayemef 08-09-2005 11:37 PM

I keep a file called ansicolor specifically for colorizing terminals (can't remember where I got the idea). It has been particularly useful with setting PS1 variables on the various machines I have to remotely administer. The nice thing about this strategy is that you can define all your color variables once, then simply import the file, whenever needed, with source /path/to/ansicolor. The file is too long to copy the entire thing, but the first portion is below. The rest of the file is exactly the same, only placing these font colors on various colored backgrounds.
Code:

# Colors on DEFAULT background.
C_BLACK="\[\033[0;30m\]"
C_GRAY_BOLD="\[\033[1;30m\]"

C_RED="\[\033[0;31m\]"
C_RED_BOLD="\[\033[1;31m\]"

C_GREEN="\[\033[0;32m\]"
C_GREEN_BOLD="\[\033[1;32m\]"

C_YELLOW="\[\033[0;33m\]"
C_YELLOW_BOLD="\[\033[1;33m\]"

C_BLUE="\[\033[0;34m\]"
C_BLUE_BOLD="\[\033[1;34m\]"

C_PURPLE="\[\033[0;35m\]"
C_PURPLE_BOLD="\[\033[1;35m\]"

C_CYAN="\[\033[0;36m\]"
C_CYAN_BOLD="\[\033[1;36m\]"

C_WHITE="\[\033[0;37m\]"
C_WHITE_BOLD="\[\033[1;37m\]"


# Color reset.
C_RESET="\[\033[0m\]"

And, to put to use (taken from my root .bashrc):
Code:

source /home/jim/bin/ansicolor
PS1="[$C_RED_BOLD\u$C_RESET@\h \W]\\$ "



All times are GMT -5. The time now is 12:29 AM.