LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-09-2012, 03:55 PM   #1
travix
LQ Newbie
 
Registered: Jul 2012
Posts: 11

Rep: Reputation: Disabled
change color of text from shell script


What command (or combination of commands) do I need to use to change the color of the text from within a shell script? My teacher has me creating a menu script where the script asks for input from the user and the user chooses from a menu of options. One of the options is the calendar utility. User can hit #4 and the cal command will run automatically. My problem is that I'm supposed to make the calendar that is printed to the screen green and I cannot for the life of me figure it out...
 
Old 07-09-2012, 04:00 PM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello and welcome to LinuxQuestions,

Posting homework verbatim will not get you any 'points' here at LQ. Although we're all here to help out LQ users with their questions/problems regarding Linux, we will not do the work for you. What have you found out up to now? Did you do a search with Google and if so what have you found? I did a quick search on Google and the following came up:
Colorizing scripts
Advanced Bash Scripting Guide

Those should get you started. Looking forward to your participation in the forums. Have fun with Linux and remember that your teacher might be a member here at LQ too.

Kind regards,

Eric
 
Old 07-09-2012, 04:11 PM   #3
travix
LQ Newbie
 
Registered: Jul 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thank you for your quick response. It's an online class and it's difficult to get the help I need. I certainly don't want anyone doing the work for me, there's still a whole script to write and I've been at it for a while now. The only thing I couldn't figure out how to do was to change the color of the output text. So you know I'm not being sneaky about my question, but am seeking help with just part of a project, here is the message I just sent my professor:

Prof,

I really cannot figure out, at all, how to change the color of the output from a shell script. I've looked on YouTube, I've looked all through the book, I've sent out a mass email to classmates (you included), I've done google searches, I've sat here at the terminal and just tried different combinations of commands and options, I've gone to the following sites:

http://losbyers.com/wordpress/2009/1...l-font-colors/

http://www.linuxhowtos.org/Tips%20an..._sequences.htm

http://www.linuxforums.org/


...and many, many more. I just cannot make it work. Would you be so kind as to walk me through how to get this done so I can get on with my last few labs? I'm beyond the point of frustration. It would be really helpful and I'd really appreciate it.

Thank You,

But if I can get this finished before he responds that would be even better.
 
Old 07-09-2012, 09:10 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
So you have mentioned that you can color the text. What else do you require? (sorry I have not used cal before)
 
Old 07-09-2012, 09:27 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Ok ... quick search on my system and found cal

As it is text based output, try changing the text color and then executing the command, within a script, and see what happens.

If stuck, show us what you are trying and we may be able to suggest options
 
Old 07-09-2012, 09:36 PM   #6
travix
LQ Newbie
 
Registered: Jul 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
changing text colors figured out

I figured it out...w/ a lot of help. My problem was I was trying to connect the processes of calling the calendar and making it green or whatever color, instead of separating the processes and first making output green with the echo -e "\033[32m" command and then on the next line calling the calendar utility. I was just stuck thinking about it in one way. Thanks for all the help!
 
Old 07-09-2012, 10:01 PM   #7
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,842

Rep: Reputation: 225Reputation: 225Reputation: 225
Code:
xterm -fg green -bg black -e cal\;bash &
 
Old 07-10-2012, 12:35 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
@teckk - whilst that is a solution it is dependent on having xterm ... what if you are simply at a command line? (ie no X)
 
Old 07-10-2012, 07:51 AM   #9
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,842

Rep: Reputation: 225Reputation: 225Reputation: 225
Code:
echo -e "\033[32m";cal
I see, I love LQ, never fail to learn something, on a weekly basis.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script to find a filename in a folder & change text within the file Simon1984 Linux - Newbie 6 05-18-2012 08:09 AM
How change text color using linux in text mode only runlevel 3? Xavius Linux - General 7 05-07-2009 03:19 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 08:15 PM
How to change Text's Color ckamheng Linux - General 7 05-10-2005 09:49 PM
how change text (and background) color within the bash shell? Xavius Linux - Newbie 4 03-29-2004 03:21 PM


All times are GMT -5. The time now is 04:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration