-
-
Save meetingattendee/5038859dc0fe9654fe8c2a990b4de42a to your computer and use it in GitHub Desktop.
A bash pretty print script that provides following red/green/blue colored echo functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "\x1b[1;31m[E] $SELF_NAME: $MESSAGE\e[0m" | |
} | |
simple_red_echo() { | |
echo -e "\x1b[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 "\x1b[1;32m[S] $SELF_NAME: $MESSAGE\e[0m" | |
} | |
simple_green_echo() { | |
echo -e "\x1b[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 "\x1b[1;34m[I] $SELF_NAME: $MESSAGE\e[0m" | |
} | |
simple_blue_echo() { | |
echo -e "\x1b[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