The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
detatchedd detatchedd is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 3
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...
  #2 (permalink)  
Old 2 Weeks Ago
TonyLawrence TonyLawrence is offline
Registered User
  
 

Join Date: Sep 2007
Location: SE Mass
Posts: 137
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`"
which leaves FAIL in white.

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.
  #3 (permalink)  
Old 2 Weeks Ago
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by TonyLawrence View Post
Use "tput"

tput setaf 2

That doesn't work on at least one of the systems I use. There are two different versions of tput. One uses termcap, the other terminfo. They are not compatible.

On the other hand, the ISO 6429 standard (also known as ECMA-48, and formerly known as ANSI X3.64), is ubiquitous, and terminals that do not support it are few and far between.

Code:
green=$(printf "\033[32m")
normal=$(printf "\033[m")
Quote:

I honestly don't like colors for scripts.

Generally, I agree with you, but there are times when it is useful.
  #4 (permalink)  
Old 1 Week Ago
TonyLawrence TonyLawrence is offline
Registered User
  
 

Join Date: Sep 2007
Location: SE Mass
Posts: 137
Yeah, I tend to forget that nobody thinks of or uses anything but Ansi nowadays :-)
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0