Last active
October 16, 2017 09:48
-
-
Save rafzei/50673d0a492bdff63cb469bd09b817f2 to your computer and use it in GitHub Desktop.
bash (scripting) colors
This file contains hidden or 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/sh | |
add_color(){ | |
#colors declaration | |
NORMAL='\\033[0m' | |
GREEN='\\033[0;32m' | |
RED='\\033[0;31m' | |
YELLOW='\\033[0;33m' | |
#recognize INFO,ERROR,SUCCESS | |
local rec_string=$(echo $1 | egrep -o '^[a-Z]{4}') | |
if [[ $rec_string == "INFO" ]]; then | |
local output_string=$(echo $1 | sed "s|INFO:|$YELLOW INFO: $NORMAL|g") | |
elif [[ $rec_string == "ERRO" ]]; then | |
local output_string=$(echo $1 | sed "s|ERROR:|$RED ERROR: $NORMAL|g") | |
elif [[ $rec_string == "SUCC" ]]; then | |
local output_string=$(echo $1 | sed "s|SUCCESS:|$GREEN SUCCESS: $NORMAL|g") | |
else | |
echo "Can't recognize string: $rec_string" | |
fi | |
echo -e $output_string | |
} | |
add_color "INFO: This is yellow output" | |
add_color "ERROR: This is red output" | |
add_color "SUCCESS: This is green output" |
Author
rafzei
commented
Sep 15, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment