help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to preserve ansi color when piping (across platform)


From: Peng Yu
Subject: Re: [Help-bash] How to preserve ansi color when piping (across platform)?
Date: Mon, 25 May 2015 05:55:27 -0500

On Sunday, May 24, 2015, Dennis Williamson <address@hidden>
wrote:

> GNU ls has the --color=always option. What are you really trying to do?
>

Some program test for tty to decide whether to use ansi color. I
deliberately use ls --color=auto as an example. I am looking for a portable
way to fool the callee to think it has a tty as it stdout.

>
>
> BTW, the version of script on my linux system needs -c to run a command:
>
> script -c 'ls -G /'
>

> On Sun, May 24, 2015 at 9:42 PM, Peng Yu <address@hidden
> <javascript:_e(%7B%7D,'cvml','address@hidden');>> wrote:
>
>> Hi,
>>
>> The following example shows how to preserver ansi color when piping.
>> But script is not compatible between mac and linux. Is there a way
>> that works across platform?
>>
>>
>> http://stackoverflow.com/questions/7641392/bash-command-preserve-color-when-piping
>>
>> ls -G /
>> ls -G / | cat
>> script -q /dev/null ls -G / | tr -d '\r' | cat
>>
>> # write output of script command to a variable
>> var="$(script -q /dev/null ls -G / | tr -d '\r' | cat)"
>> echo "$var"
>>
>> --
>> Regards,
>> Peng
>>
>>
>
>
> --
> Visit serverfault.com to get your system administration questions
> answered.
>


-- 
Regards,
Peng


reply via email to

[Prev in Thread] Current Thread [Next in Thread]