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 = ^[ = \e
In searching I found this question about detecting slash-escaped support.
The selected answer sniffs the
$TERM value to detect
case $TERM in (|color(|?))(([Ekx]|dt|(ai|n)x)term|rxvt|screen*)*) PS1=$'\e\]0;$GENERATED_WINDOW_TITLE\a'"$PS1" esac
But 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 most wide-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?
This is a nice read too for anyone else looking for info.