To avoid a subshell, what are the ANSI escape equivalents of tput sgr0 for an ANSI-compatible terminal?


You could answer that by looking at the output of infocmp: using the -1 option to print one capability per line for a given setting of TERM (i.e., "ansi"), simplifying a grep:

infocmp -1 ansi |grep sgr0=

and seeing (for example)


which tells you that you could do

printf '\033[0;10m'

to get the same effect as

tput -T ansi sgr0

But you're not using ANSI, but rather some particular terminal, and though the ones you're using are similar, not all are identical. It's more likely that your TERM variable is set to something like "xterm", which (omitting the terminal type) gives


The common part is the \E[m, which is the terminfo syntax for \033[m. The other characters in each sequence are resetting the alternate character set (and can depend on the terminal type).

  • Is ansi an option? Aug 18 '20 at 12:00
  • 1
    -T ansi is an option, telling tput which terminal description to use. Aug 18 '20 at 18:29
  • Please consider explaining the entire command, e.g. -1 ansi, so I don't have to look it up or test personally to see that results in each variable printing on its own line.
    – Sinjai
    Jan 18 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.