Bash ansi escape codes

From wikinotes
Revision as of 00:56, 10 February 2021 by Will (talk | contribs) (→‎Colours)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Terminals are controled ansi escape sequences.
These sequences vary from terminal to terminal.
The tput command uses your terminal's termcap library to expose a common interface.

Colours

See list of colours https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit

echo -e '\e[32m'     # 
echo -e '\e[m'       # reset colour

tput setab 7 # set bg colour
tput setaf 7 # set fg colour
tput bold    # set bold
tput sgr0    # reset colours

yellow=$(tput setaf 3)
echo "${yellow}foo"