Sterling Hamilton

13 Oct, 2008

Nifty Shell Script Function

Posted by: Sterling Hamilton In: Code

Need to style some of that text in your script?

Well then use this bad boy:

#!/bin/bash
#
# Example usage:
# echo ${RedF}This text will be red!${Reset}
# echo ${BlueF}{$BoldOn}This will be blue and bold!${BoldOff} - and this is just blue!${Reset}
# echo ${RedB}${BlackF}This has a red background and black font!${Reset}and everything after the reset is normal text!
 
Colors() {
  Escape="\033";
 
  BlackF="${Escape}[30m";   RedF="${Escape}[31m";   GreenF="${Escape}[32m";
  YellowF="${Escape}[33m";  BlueF="${Escape}[34m";    Purplef="${Escape}[35m";
  CyanF="${Escape}[36m";    WhiteF="${Escape}[37m";
 
  BlackB="${Escape}[40m";     RedB="${Escape}[41m";     GreenB="${Escape}[42m";
  YellowB="${Escape}[43m";    BlueB="${Escape}[44m";    PurpleB="${Escape}[45m";
  CyanB="${Escape}[46m";      WhiteB="${Escape}[47m";
 
  BoldOn="${Escape}[1m";      BoldOff="${Escape}[22m";
  ItalicsOn="${Escape}[3m";   ItalicsOff="${Escape}[23m";
  UnderlineOn="${Escape}[4m";     UnderlineOff="${Escape}[24m";
  BlinkOn="${Escape}[5m";   BlinkOff="${Escape}[25m";
  InvertOn="${Escape}[7m";  InvertOff="${Escape}[27m";
 
  Reset="${Escape}[0m";
}

No Responses to "Nifty Shell Script Function"

Comment Form

You must be logged in to post a comment.

Categories

Archives

About

Hi, You’ve found my website, well done!

I’m a web designer and an all round geek, hence the funky website. I live in Reno and work in Carson City with a great group of web developers.

I’d describe myself as quiet, shy and simply a nice guy - but I’d be lying. But one can try right? I like my music rocking, my tea hot, and my shoes custom, as well as my daily dose of caffeine, gaming and technology.

I rock green eyes, curly brown hair which I tend to keep on the long side, and a complexion that can be illustrated with a blank sheet of paper. I dress business casual most of the time or just casual and I drive the most generic car on the planet.