[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to preserve ansi color when piping (across platform)
Re: [Help-bash] How to preserve ansi color when piping (across platform)?
Tue, 26 May 2015 08:27:37 -0400
On Mon, May 25, 2015 at 05:55:27AM -0500, Peng Yu wrote:
> Some program test for tty to decide whether to use ansi color. I
> deliberately use ls --color=auto as an example.
"All examples given by the questioner will be broken, misleading, wrong,
incomplete, and/or not representative of the actual question." (!b9)
> I am looking for a portable
> way to fool the callee to think it has a tty as it stdout.
You may want expect, or pexpect, or empty, or some similar program.
There IS NO OTHER GENERAL SOLUTION, and typically what you want is a
specific option included in the program you are actually working with,
such as --color=always. That's why people get upset when you make up
bad examples instead of showing the actual problem.
In any case, these "general solutions" are not part of bash, nor of
the standard POSIX utility set, and are not really on topic in a bash
help list. If your REAL PROGRAM has no option to force terminal-ish
output, then you need external programs as I mentioned above, and all
of them are written in a language other than bash (the three I mentioned
are written in Tcl, Python and C, respectively).