Mailinglist Archive: opensuse-de (2154 mails)

< Previous Next >
Re: OT: farbige ausgabe mittels "echo"
  • From: gooly@xxxxxx
  • Date: Wed, 28 Feb 2007 09:33:21 +0100
  • Message-id: <200702280933.22081.gooly@xxxxxx>
Am Mittwoch, 28. Februar 2007 09:24 schrieb Dr. Jürgen Vollmer:
> Hallo allerseits,
>
> ich denke doch mal, daß man mit dem Shell-Befehle "echo" auch farbige
> Texte auf die Konsole zaubern kann. Nur wie?
>
> Bin für jeden Tip dankbar.

Jürgen, ich hab mir das mal gespeichert..

Farbige (color, colour) Text Consolen ausgabe:
http://linuxreviews.org/beginner/abs-guide/en/x14513.html#COLORECHO
(Der Link schein leider tot..)

Color Foreground Background
black 30 40
red 31 41
green 32 42
yellow 33 43
blue 34 44
magenta 35 45
cyan 36 46
white 37 47

Example 34-10. Echoing colored text

#!/bin/bash
# color-echo.sh: Echoing text messages in color.

# Modify this script for your own purposes.
# It's easier than hand-coding color.

black='\E[30;47m'
red='\E[31;47m'
green='\E[32;47m'
yellow='\E[33;47m'
blue='\E[34;47m'
magenta='\E[35;47m'
cyan='\E[36;47m'
white='\E[37;47m'


alias Reset="tput sgr0" # Reset text attributes to normal
#+ without clearing screen.


cecho () # Color-echo.
# Argument $1 = message
# Argument $2 = color
{
local default_msg="No message passed."
# Doesn't really need to be a local
variable.

message=${1:-$default_msg} # Defaults to default message.
color=${2:-$black} # Defaults to black, if not specified.

echo -e "$color"
echo "$message"
Reset # Reset to normal.

return
}


# Now, let's try it out.
# ----------------------------------------------------
cecho "Feeling blue..." $blue
cecho "Magenta looks more like purple." $magenta
cecho "Green with envy." $green
cecho "Seeing red?" $red
cecho "Cyan, more familiarly known as aqua." $cyan
cecho "No color passed (defaults to black)."
# Missing $color argument.
cecho "\"Empty\" color passed (defaults to black)." ""
# Empty $color argument.
cecho
# Missing $message and $color arguments.
cecho "" ""
# Empty $message and $color arguments.
# ----------------------------------------------------

echo

exit 0

Perl-Farbig:
use Term::ANSIColor;
print color 'bold blue';
print "This text is bold blue.\n";
print color 'reset';
print "This text is normal.\n";
print colored ("Yellow on magenta.\n", 'yellow on_magenta');
print "This text is normal.\n";
print colored ['yellow on_magenta'], "Yellow on magenta.\n";


--
Um die Liste abzubestellen, schicken Sie eine Mail an:
opensuse-de+unsubscribe@xxxxxxxxxxxx
Um eine Liste aller verfuegbaren Kommandos zu bekommen, schicken
Sie eine Mail an: opensuse-de+help@xxxxxxxxxxxx

< Previous Next >
References