| 0 | Black |
| 1 | Red |
| 2 | Green |
| 3 | Yellow |
| 4 | Blue |
| 5 | Magenta |
| 6 | Cyan |
| 7 | White |
| 8 | Not used |
| 9 | Reset to default color
|
Example
green=`tput setaf 2`
red=`tput setaf 2`
reset=`tput sgr0`
echo -e "\n${green}########## Display Text in GREEN Color ########## ${reset} \n"
echo -e "\n${red}########## Display Text in RED Color ########## ${reset} \n"
Customize Bash Prompt in Linux
#Set it permnently
sudo nano ~/.bashrc
#at the end of the file, paste the below and save it
PS1="\e[1;34m[\u - \W]\$ \e[0m"
#u = username; \H = hostname;
export PS1="\u# "
#Hide everything
export PS1="\W > "
#Show Username with last Directory in color
export PS1="\e[0;32m[\u - \W]\$ \e[0m"
export PS1="\e[1;34m[\u - \W]\$ \e[0m"
• \e[ – Begin color changes
• 0;32m – Specify the color code
• [\u@\h \W]\$ – This is the code for your normal BASH prompt (username@hostname Workingdirectory $)
• \e[0m – Exit color-change mode
The first number in the color code specifies the typeface:
• 0 – Normal
• 1 – Bold (bright)
• 2 – Dim
• 4 – Underlined
The second number indicates the color you want:
• 30 – Black
• 31 – Red
• 32 – Green
• 33 – Brown
• 34 – Blue
• 35 – Purple
• 36 – Cyan
• 37 – Light gray
Referenec: https://phoenixnap.com/kb/change-bash-prompt-linux
Comments
Post a Comment