LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   change color of text from shell script (https://www.linuxquestions.org/questions/linux-newbie-8/change-color-of-text-from-shell-script-4175415756/)

travix 07-09-2012 02:55 PM

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...

EricTRA 07-09-2012 03:00 PM

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

travix 07-09-2012 03:11 PM

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.

grail 07-09-2012 08:10 PM

So you have mentioned that you can color the text. What else do you require? (sorry I have not used cal before)

grail 07-09-2012 08:27 PM

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 :)

travix 07-09-2012 08:36 PM

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!

teckk 07-09-2012 09:01 PM

Code:

xterm -fg green -bg black -e cal\;bash &

grail 07-09-2012 11:35 PM

@teckk - whilst that is a solution it is dependent on having xterm ... what if you are simply at a command line? (ie no X)

teckk 07-10-2012 06:51 AM

Code:

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


All times are GMT -5. The time now is 11:32 PM.