Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
if i pipe from /proc/${$}/fd/0 it seems to work but i don`t kno why – Prospero Jul 21 '13 at 7:57
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. – Prospero 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.
share|improve this answer
this confirms my thinking very useful, ty – Prospero Jul 24 '13 at 19:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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