RSS Forums RSS
Please support our Shell Scripting advertiser: Programming Forums
Views: 1136 | Replies: 4 | Solved | Thread Tools  Display Modes
Reply
Join Date: Jun 2008
Posts: 26
Reputation: krammer is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
krammer krammer is offline Offline
Light Poster

Colors in bash

  #1  
Jul 17th, 2008
I'm trying to add colors to this bash script, can anyone help?

#!/bin/bash
# Script to connect to the sprint network

# Colors
# ESC_SEQ=“\x1b[“
COL_RESET=$ESC_SEQ“39;49;00m“
COL_RED=$ESC_SEQ“31;01m“
COL_GREEN=$ESC_SEQ“32;01m“
COL_YELLOW=$ESC_SEQ“33;01m“
COL_BLUE=$ESC_SEQ“34;01m“
COL_MAGENTA=$ESC_SEQ“35;01m“
COL_CYAN=$ESC_SEQ“36;01m“

case "$1" in

connect)
	pppd call sprint updetach
	echo -e $COL_GREEN"**You are now connected to the sprint network!"$COL_RESET
	;;

disconnect)
	killall pppd
	echo -e $COL_RED"**You have disconnected from the sprint network!"$COL_RESET
	;;

esac

Here are the errors:

root@mybox:~/Scripts# ./sprint disconnect
./sprint: line 6: 49: command not found
./sprint: line 6: 00m“: command not found
./sprint: line 7: 01m“: command not found
./sprint: line 8: 01m“: command not found
./sprint: line 9: 01m“: command not found
./sprint: line 10: 01m“: command not found
./sprint: line 11: 01m“: command not found
./sprint: line 12: 01m“: command not found
“31**You have disconnected from the sprint network!“39
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Posts: 26
Reputation: krammer is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
krammer krammer is offline Offline
Light Poster

Re: Colors in bash

  #2  
Jul 17th, 2008
Sorry actually this is the error:

root@mybox:~/Scripts# ./sprint disconnect
./sprint: line 6: 49: command not found
./sprint: line 6: 00m“: command not found
./sprint: line 7: 01m“: command not found
./sprint: line 8: 01m“: command not found
./sprint: line 9: 01m“: command not found
./sprint: line 10: 01m“: command not found
./sprint: line 11: 01m“: command not found
./sprint: line 12: 01m“: command not found
“x1b[““31**You have disconnected from the sprint network!“x1b[““39

I uncommented
# ESC_SEQ=“\x1b[“

I was just doing that for testing...
Reply With Quote  
Join Date: Jun 2008
Posts: 26
Reputation: krammer is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
krammer krammer is offline Offline
Light Poster

Re: Colors in bash

  #3  
Jul 17th, 2008
This is working....but not exactly the way i'd like for variables:

#!/bin/bash
# Script to connect to the sprint network

# Colors
#ESC_SEQ='\x1b['
#COL_RESET='; tput sgr0'
#COL_RESET=$ESC_SEQ“39;49;00m“
COL_RED='\E[31;01m'
COL_GREEN='\E[32;01m'
COL_YELLOW='\E[33;01m'
COL_BLUE='\E[34;01m'
COL_MAGENTA='\E[35;01'
COL_CYAN='\E[36;01m'


case "$1" in

connect)
	pppd call sprint updetach
	echo -e "$COL_GREEN**You are now connected to the sprint network!" ; tput sgr0
	;;

disconnect)
	killall pppd
	echo -e "$COL_RED**You have disconnected from the sprint network!" ; tput sgr0
	;;

esac
Reply With Quote  
Join Date: Oct 2007
Posts: 356
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Rep Power: 3
Solved Threads: 36
eggi eggi is offline Offline
Posting Whiz

Re: Colors in bash

  #4  
Jul 17th, 2008
Hey there,

It may just be an issue with calling the variables.

If you change

COL_GREEN='\E[32;01m'

to

COL_GREEN="\033[32;1m"

it might work better with the "echo -e" line.

Hope that helps

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Earn 100% commissions on ClickBank. No Opt-In Or Upsell. Check out the Ultimate ClickBank SuperTip
Reply With Quote  
Join Date: Jun 2008
Posts: 26
Reputation: krammer is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
krammer krammer is offline Offline
Light Poster

Re: Colors in bash

  #5  
Jul 23rd, 2008
Sorry I haven't tried it. What I changed is working fine now...I was just trying to replace the "tput sgr0" with a variable...unless someone knows how to do that. I couldn't get it working right...probably was going wrong with the single and double quotes.

If no one knows then I'll mark this as solved.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the Shell Scripting Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 8:34 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC