tput
noun
say it: “TEE-put” /ˈtiˌpʊt/
A command that prints the code a terminal reads as a style or color, chosen by name, such as bold or green.
What does tput do?
tput prints the hidden code your terminal reads as a style or color, so you name the style instead of remembering escape codes. tput bold turns on bold, tput setaf 2 green text, and tput sgr0 goes back to normal. Use it only when [[ -t 1 ]] says the output is going to a screen.
green=$(tput setaf 2)
reset=$(tput sgr0)
echo "${green}Added Grilled Cheese.${reset}" # Added Grilled Cheese. (in green)
In a sentence
- “tput setaf 2 turned the word Added green.”
- “Sam uses tput sgr0 to switch the text back to normal.”
Level: Journeyman · More Unix terms at this level
Updated