I'm not sure if this is something anyone will find valuable but it's been a neat little addition to my scripting as of late.
For those who have used Cucumber in the past for BDD, one of the visible elements is of course there paradigm of green, yellow and red text that appears for a variety of things in your output on the screen. This division also helps me quickly monitor if something seems out of place or if a command I expect to run completes correctly or not. as I do a lot with shell scripts, I decided to do some research and see if I could add a bit of that green, yellow, red (and for some variety I even added blue to the mix). Here's how you can do that.
First, the echo command allows for ANSI escape codes to be called and change the color of text. To do this, you first call echo with the '-e' flag and then for the word or words you want to highlight with a different color. You can see a list of ANSI escape codes and colors here. For my purposes, here's an example of a set of codes I keep is a shared shell library:
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
RESET="\033[0m"
In practice, any time you use an echo -e statement, you can determine if the output you see is normal/expected, if it's an error, if it's a possible warning that doesn't rise to the level of an error, or if you want to display some information that fits some other purpose. Also, once you set a color, that color will remain in place unless you reset back to the default color option.
In practice it looks like this:
echo -e "${RED}Usage: $0 [CUSTOMER] [DUNS] [VERSION] [TEST_TYPE] [filename] ${RESET}"
exit 1
fi