Skip to content

Instantly share code, notes, and snippets.

@dwallraff
Created September 13, 2016 17:06
Show Gist options
  • Save dwallraff/2ed1ddf05967879bf81ef3a402b298f3 to your computer and use it in GitHub Desktop.
Save dwallraff/2ed1ddf05967879bf81ef3a402b298f3 to your computer and use it in GitHub Desktop.
Use `tput` to modify output in bash scripts
NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
function red() {
echo -e "$RED$*$NORMAL"
}
function green() {
echo -e "$GREEN$*$NORMAL"
}
function yellow() {
echo -e "$YELLOW$*$NORMAL"
}
# To print success
green "Task has been completed"
# To print error
red "The configuration file does not exist"
# To print warning
yellow "You have to use higher version."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment