ANSI escape sequences, how to enter escape character from keyboard? [closed]
The escape key can be generated with the backslash sequence \e
in a command which interprets backslash sequences.
eg:
echo -e "Text can be \e[1;41mred\e[m or \e[1;45mmagenta\e[m"for back in {30..37}; do echo -n $back: for fore in {40..47}; do printf "\e[1;%2d;%2dm%2d\e[m " $back $fore $fore done printf "\n"done
A possibility not illustrated above is the bash escape interpreted string: $'\e[1m'
.
Although using vt escape sequences (as above) is easy and supported by most if not all commonly-used unix terminal emulators, die-hards will insist that you learn to use the tput
command:
printf "Here is a %sbold red%s word\n" "$(tput bold)""$(tput setf 4)" "$(tput sgr0)"
IMHO, figuring out the magic tput symbols (see man 5 terminfo
on a debian/ubuntu system) is not as easy as looking up the xterm control sequences (google the last three words), but YMMV.