Tuesday, May 7, 2024
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 764  / 1 Year ago, sat, april 8, 2023, 8:45:19

I was trying to remember how I could pre-define colors inside of .bashrc file so they could be called on when I do ${RED} for example.



I can't remember if this was the right way of doing it, but it was something like this if I can remember;



NC="033[0;0;0m"      # no color or formatting
RED="033[1;49;91m" # color red
BLU="033[1;49;94m" # color blue
GRN="033[1;49;32m" # color green


another I recall, was using function so it could be use at any time anywhere. I did have a file showing me how to do this but I lost this file which showed how to do it, and I can't remember how it goes.


More From » command-line

 Answers
1

You can define a function in your ~/.bashrc as follows



showred(){
export RED='033[1;49;91m'
export NC='033[0;0;0m'
echo -e $RED"$@"$NC
}


Source ~/.bashrc as . ~/.bashrc or open a new terminal and try.



enter image description here



Also you can write in colours while writing something on terminal using echo or printf as following,



enter image description here


[#21121] Monday, April 10, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tisglitter

Total Points: 307
Total Questions: 103
Total Answers: 119

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
;