Categories
Openbsd

Adding color, colour to bash scripts

I was curious about just adding colour to echos that I do in scripts and here is how:

echo -e "This is red->e[00;31mREDe[00m"

 

I havent found out how the colours actually work (eg tables of colours) but if you experiment with the numbers you can come up with different foreground and background colours.

UPDATE:

Ok here is a script to dump out the various colour combos.

#/bin/sh
# Show all the colors of the rainbow, should be run under bash
for STYLE in 0 1 2 3 4 5 6 7; do
  for FG in 30 31 32 33 34 35 36 37; do
    for BG in 40 41 42 43 44 45 46 47; do
      CTRL="33[${STYLE};${FG};${BG}m"
      echo -en "${CTRL}"
      echo -n "${STYLE};${FG};${BG}"
      echo -en "33[0m"
    done
    echo
  done
  echo
done
# Reset
echo -e "33[0m"