Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[geloest] farbige ausgabe von text
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
tzzaetaynzz
Apprentice
Apprentice


Joined: 29 Sep 2003
Posts: 221

PostPosted: Wed Feb 08, 2006 8:55 pm    Post subject: [geloest] farbige ausgabe von text Reply with quote

hallo an alle,

ich habe in einen shellskript einige ausgaben mit einer anderen farbe (rot)
als der standardfarbe (gruen) versehen,
um sie hervor zu heben.
Code:
      1 #!/bin/bash
      2 read -ep "Text [ A `tput setaf 1` B `tput setaf 2` C]: " BLA
      3 echo $BLA

die ausgabe sieht so aus:
Code:
[admin@emma ~]$ ./test.sh
Text [ A  B  C]: A
A

naja, und das B ware eigentlich rot. :)
gibt es auch eine elegantere loesung?
_________________
gruss //tzzaettaynzz

---

„Have you tried turning it off and on again?“


Last edited by tzzaetaynzz on Sun Feb 12, 2006 10:41 am; edited 1 time in total
Back to top
View user's profile Send private message
schmutzfinger
Veteran
Veteran


Joined: 26 Oct 2003
Posts: 1287
Location: Dresden/Germany

PostPosted: Thu Feb 09, 2006 12:06 am    Post subject: Reply with quote

Code:

#!/bin/sh
echo "^[[1;31m hallo ^[[0m"


das "^[" ist nicht "^"."[" sondern Escape. Escape kannst du mit vim im insert mode mit "strg+v" "escape" einfügen. Und dann copy paste ;). Die Farbnummern kannst du zB in /etc/DIR_COLORS ablesen.
Back to top
View user's profile Send private message
DarKRaveR
Guru
Guru


Joined: 11 Oct 2003
Posts: 500
Location: Old Europe/G-Many

PostPosted: Thu Feb 09, 2006 3:41 am    Post subject: Reply with quote

alternativ:

Code:
echo -e


und dann das escape mit \e angeben.

also summa sumarum:

Code:
echo -e "\e[1;31m hallo"


um beim beispiel des Vorposters zu bleiben ...
Back to top
View user's profile Send private message
tzzaetaynzz
Apprentice
Apprentice


Joined: 29 Sep 2003
Posts: 221

PostPosted: Fri Feb 10, 2006 9:12 am    Post subject: Reply with quote

@DarKRaveR
@schmutzfinger

danke fuer eure tips!
leider habe ich in meinem posting nur die halbe warheit geschrieben;
die farben moechte ich waehrend eines "read" aufrufes aendern.
und dabei kommt es so (tput) oder so (escapesequenz) zu fehlerhaften darstellungen.
Code:
read -ep "Pfad ^[[1;31m $PFAD_ALT ^[[0m: " PFAD


im gnome-terminal:
Code:

: ad  /home/admin/arno_sagawe-dokumente/aktenordner/emma/quittungen-2004


im multi-gnome-terminal:
Code:
: ad  /home/admin/arno_sagawe-dokumente/aktenordner/emma/quittungen-2004


ebenso im xterm.

nur auf der "echten console" (strg+alt+f1) funktioniert die ausgabe einwandfrei.

habt ihr eine idee,
was ich meinen terminals bekannt geben muss,
damit die darstellung funktioniert?

[12.02.2006]

hallo an alle,

nun habe ich eine loesung gefunden:
Code:
   echo -en "Pfad [\033[1;31m$PFAD_ALT\033[0m]: "
   read -ep '' PFAD

1. echo ohne zeilenumbruch und mit esc, gibt den prompttext aus
2. read ohne text '', setzt den curser hinter ": " von echo

somit sieht die ausgabe wie folgt aus

Pfad [/home/user/]:
_________________
gruss //tzzaettaynzz

---

„Have you tried turning it off and on again?“
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum