I am playing around with shell scripts that use ANSI codes and found that for one reason or another different escape codes are supported depending on your terminal/OS.In some cases I get a dump of unparsed gunk unexpectedly, which I'm assuming means my terminal (on Mac OS) doesn't support that escape code used, despite having read in a number of places that these mean the same thing:27 = 033 = 0x1b = ^[ = \eIn searching I found this question about detecting slash-escaped support.The selected answer sniffs the $TERM value to detectcase $TERM in  (|color(|?))(([Ekx]|dt|(ai|n)x)term|rxvt|screen*)*)    PS1=$'\e\]0;$GENERATED_WINDOW_TITLE\a'$PS1esacBut I wonder how reliable that is.Is there a standard way to check for escape code support (primarily for Bash), or is that script pretty much the run of the mill?Alternatively, what escape code can I use to 'guarantee' the mostwide-spread support?What about echo expansion -e?What are general best practices in terms of portability/availability/distribution for scripts that use or reference control codes?I'm pretty green to deeper *nix nuances and terminal sessions, so be gentle. This is a nice read too for anyone else looking for info.
Programmatically detect the ANSI escape code supported by terminal
terminal;escape characters;ansi term
Have you got specific operations in mind?Here is an example of using standout mode, which on many terminals will give a strong visible result:tput smso; echo hello, world; tput rmsoIf you were to pipe the sequence to, say, cat, the highlighting would become an empty operation because a pipe isn't a device that understands standout mode:( tput smso; echo hello, world; tput rmso ) | catInteresting characteristic pairs can be found in man 5 terminfo, some of which are as follows:Standout: smso and rmsoUnderline: smul and rmulBlink (yes!): blinkDoublewide: swidm and rwidmReverse: revCancel all: sgr0