Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

script with colors

Caesar_3
Esteemed Contributor

script with colors

Hello

How can i write with color in perl or some shell in linux (RH 7.2 or high).
Which command or modules can help?

Thk
Caesar
5 REPLIES
Jerome Henry
Honored Contributor

Re: script with colors

I would use vim for just editing purpose (quite a bit of learning to use, though, but you'll get trhough in 20 mn typing 'vimtutor'),
and for debugging... emacs.
hth
J
You can lean only on what resists you...
Caesar_3
Esteemed Contributor

Re: script with colors

I mean that i want to write a script on perl or shell that will write text with color!
Jerome Henry
Honored Contributor

Re: script with colors

Oops,
sorry Caesar for misunderstanding. What you need is the curses and ncurses function in your script.
man these functions or look at this howto about ncurses, the new curses. Notice that it exists both for shell & perl :
http://www.linux.org/docs/ldp/howto/NCURSES-Programming-HOWTO/
hth
J
You can lean only on what resists you...
Francisco J. Soler
Honored Contributor

Re: script with colors

Hi, Caesar

I've found this. Try it, i think is what you want.

You can found more information at:
http://www.freeos.com/guides/lsst/

Cheers Frank.

#!/bin/bash
#
# Linux Shell Scripting Tutorial 1.05r3, Summer-2002
#
# Written by Vivek G. Gite
#
# Latest version can be found at http://www.nixcraft.com/
#
# Q16
# echo command with escape sequance to give differnt effects
#
# Syntax: echo -e "escape-code your message, var1, var2 etc"
# For eg. echo -e "\033[1m Hello World"
# | |
# | |
# Escape code Message
#

clear
echo -e "\033[1m Hello World"
# bold effect
echo -e "\033[5m Blink"
# blink effect
echo -e "\033[0m Hello World"
# back to noraml

echo -e "\033[31m Hello World"
# Red color
echo -e "\033[32m Hello World"
# Green color
echo -e "\033[33m Hello World"
# See remaing on screen
echo -e "\033[34m Hello World"
echo -e "\033[35m Hello World"
echo -e "\033[36m Hello World"

echo -e -n "\033[0m "
# back to noraml

echo -e "\033[41m Hello World"
echo -e "\033[42m Hello World"
echo -e "\033[43m Hello World"
echo -e "\033[44m Hello World"
echo -e "\033[45m Hello World"
echo -e "\033[46m Hello World"


echo -e "\033[0m Hello World"
# back to noraml
Linux?. Yes, of course.
Stuart Browne
Honored Contributor

Re: script with colors

Go Francisco! :)

Caeser, welcome to the wonderful world of ANSI Escape sequences!

It's truely quite remarkable what you can do with these silly things (I remember re-mapping CTRL-C using ANSI.SYS on old DOS 5 systems!), but it all goes down to terminal emulation requirements.

If you are using a VT220 terminal, or emulation, you'll have issues with using ANSI color sequences.

But as you'll most probably be using some emulator that does ANSI anyway (as it's extremely widely used, and a number of other emulation types use a subset of it's sequences), you shouldn't have too many issues.

Strangely enough, if you look in the "Bash-Prompt-HOWTO" (section 6 - http://www.ibiblio.org/mdw/HOWTO/Bash-Prompt-HOWTO/), you'll find quite a few details on what you can do with your shell.

Have fun.. ;)
One long-haired git at your service...