![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help with changing bash to perl | freak | UNIX for Dummies Questions & Answers | 3 | 07-01-2008 10:44 AM |
| changing text | outthere_3 | Shell Programming and Scripting | 2 | 02-13-2008 12:46 AM |
| changing last 2 digits of text | kingdbag | Shell Programming and Scripting | 4 | 11-07-2006 05:51 PM |
| HOw to change the text colour through shell script? | Sona | UNIX for Dummies Questions & Answers | 7 | 09-05-2005 01:57 AM |
| Changing text with sed? | primal | UNIX for Dummies Questions & Answers | 2 | 01-12-2002 09:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Changing text colour in bash
I am doing a basic script to check if services are disabled, and I was wondering how to change to colours for PASS and FAIL to green & red respectively.
Code:
#!/usr/bin/bash
clear
TELNET=`svcs -a | grep telnet | awk '{print $1}'`
if [ "$TELNET" == "disabled" ]
then
RESULT=PASS
else
RESULT=FAIL
fi
echo -e "Verifying if Telnet services are disabled [$RESULT]"
FTP=`svcs -a | grep ftp | awk '{print $1}'`
if [ "$FTP" == "disabled" ]
then
RESULT2=PASS
else
RESULT2=FAIL
fi
echo "Verifying if FTP services are disabled [$RESULT2]"
Last edited by pludi; 2 Weeks Ago at 11:38 AM.. Reason: code tags, please... |
|
||||
|
Use "tput"
tput setaf 2 echo Green tput setaf 1 echo Red tput setaf 7 echo normal See man tput and the "Color Handling" section of "man terminfo" ---------- Post updated at 05:33 AM ---------- Previous update was at 05:20 AM ---------- Oh, and by the way: I wouldn't do that unless you are the only one to use the script. Color is tricky. Displays can be bad at it, people can be color blind... I might do this: Code:
echo "`tput setaf 1` **** `tput setaf 7` FAIL `tput setaf 1` *** `tput setaf 7`" But even at that you have to be trickier. This would be awful on a white background - "FAIL" would be invisible. I honestly don't like colors for scripts. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|