this is the script color


  case $1 in
    red )    COL_START=$ESC_SEQ"31;01m"
    green)   COL_START=$ESC_SEQ"32;01m"
    yellow ) COL_START=$ESC_SEQ"33;01m"
    blue )   COL_START=$ESC_SEQ"34;01m"
    mage )   COL_START=$ESC_SEQ"35;01m"
    cyan )   COL_START=$ESC_SEQ"36;01m"

  echo -ne $COL_START
  while read text;
  echo  $text
  echo -ne $COL_RESET

when i do

curl localhost:8080/

it responds with the usual curl outputm HOOOOORAY!

when i do

curl localhost:8080/ | color red

it does not color the output how I expect it to ...... `CRY'

I don`t think I am calling read correctly for the situation.

  • if i pipe from /proc/${$}/fd/0 it seems to work but i don`t kno why – Arcabard Jul 21 '13 at 7:57
  • 1
    It works for me with curl :[ You may be interested in this: cognitivedissonance.ca/cogware/utf8_colorize/… There's a README in the tarball. – goldilocks Jul 21 '13 at 9:14
  • what an intense little script, never know though when you might have to drop 80 000 000 emails though. – Arcabard Jul 24 '13 at 19:01

It works for me exactly as you have laid out in the questions. You may want to check to see that your escapes are correct. They might not be the correct escapes for your $TERM which can be easily fixed by using tput to query for the correct escapes for you like so:

COL_RESET=$(tput sgr0)
red )    COL_START=$(tput setaf 1)
green )    COL_START=$(tput setaf 2)
blue )    COL_START=$(tput setaf 4)

Another example of using these can be found here.

You also may want to change the way you call echo in case you are getting interference there. The man page for echo suggests the following:

Due to shell aliases and built-in `echo' command, using an unadorned `echo' 
interactively or in a script may get you different functionality than that
described here.  Invoke it via `env' (i.e., `env echo ...') to avoid
interference from the shell.
  • this confirms my thinking very useful, ty – Arcabard Jul 24 '13 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.