Skip to content

Instantly share code, notes, and snippets.

@nehaljwani
Forked from amberj/rgb-colored-echo.sh
Created June 20, 2014 19:58
Show Gist options
  • Save nehaljwani/b5d9b0591f05626e42b2 to your computer and use it in GitHub Desktop.
Save nehaljwani/b5d9b0591f05626e42b2 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
## @file rgb-colored-echo.sh
## @author Amber Jain
## @section DESCRIPTION A bash pretty print script which provides red/green/blue colored echo functions
## @section LICENSE ISC
#################
# Documentation #
#################
#
# A bash pretty print script which provides following red/green/blue colored echo functions:
# red_echo
# simple_red_echo
# green_echo
# simple_green_echo
# blue_echo
# simple_blue_echo
#
# Simple copy/paste function definitions or 'source' this script in your bash script and then you can use these functions.
##########################
# Start of script 'body' #
##########################
SELF_NAME=$(basename $0)
# Prints warning/error $MESSAGE in red foreground color
#
# For e.g. You can use the convention of using RED color for [E]rror messages
red_echo() {
echo -e "\e[1;31m[E] $SELF_NAME: $MESSAGE\e[0m"
}
simple_red_echo() {
echo -e "\e[1;31m$MESSAGE\e[0m"
}
# Prints success/info $MESSAGE in green foreground color
#
# For e.g. You can use the convention of using GREEN color for [S]uccess messages
green_echo() {
echo -e "\e[1;32m[S] $SELF_NAME: $MESSAGE\e[0m"
}
simple_green_echo() {
echo -e "\e[1;32m$MESSAGE\e[0m"
}
# Prints $MESSAGE in blue foreground color
#
# For e.g. You can use the convetion of using BLUE color for [I]nfo messages
# that require special user attention (especially when script requires input from user to continue)
blue_echo() {
echo -e "\e[1;34m[I] $SELF_NAME: $MESSAGE\e[0m"
}
simple_blue_echo() {
echo -e "\e[1;34m$MESSAGE\e[0m"
}
#########
# Usage #
#########
echo "This is a 'normal' echo!"
echo
MESSAGE="This is a RED colored message!" ; red_echo
MESSAGE="This is a simple RED colored message!" ; simple_red_echo
echo
MESSAGE="This is a GREEN colored message!" ; green_echo
MESSAGE="This is a simple GREEN colored message!" ; simple_green_echo
echo
MESSAGE="This is a BLUE colored message!" ; blue_echo
MESSAGE="This is a simple BLUE colored message!" ; simple_blue_echo
#################
# End of script #
#################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment