GNU bug report logs - #21919
tee enhancement

Previous Next

Package: coreutils;

Reported by: "Tim Shaw" <timshaw <at> mail.usa.com>

Date: Sat, 14 Nov 2015 16:09:01 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 21919 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Tim Shaw <timshaw <at> mail.usa.com>, 21919 <at> debbugs.gnu.org
Subject: Re: bug#21919: tee enhancement
Date: Mon, 16 Nov 2015 00:23:38 +0000
tag 21919 notabug
close 21919
stop

On 15/11/15 23:59, Pádraig Brady wrote:
> On 14/11/15 16:00, Tim Shaw wrote:
>> If I am using stdout redirection of a shell block to capture some text I am generating, errors need to go to stderr, but it would also be good if they went into the generated output. For example
>> for i in files*; do
>>   if there_is_an_error; then
>>     echo big long complicated error message goes here >&2
>>     echo big long complicated error message goes here
>>     continue
>>   fi
>>    stuff_producing_text_on_stdout
>> done > file_i_am_creating
>>  
>> I do not like duplicating code, such as the big long error message echo. So, I could create a temp file or a temp shell var to save the message, but that makes things more complicated than just duplicating the code, and also is just not my style for something transient like this.
>>  
>> What I would like to do is add a parameter to tee, "-2", that copies to stderr in addition to stdout, just like "-" copies to stdout twice. 
> 
> Note `tee -` now copies to a file called '-' rather than
> duplicating to stdout, since v8.24 as discussed at:
> http://lists.gnu.org/archive/html/coreutils/2015-02/msg00085.html
> 
>> So the code becomes
>>     echo big long complicated error message goes here | tee -2
>> Simple, eh?
>>  
>> Where's the tee source?

tee source is at http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/tee.c

> I know this would not be POSIX compliant, but it would work for me, and I hate having to rewrite everything from scratch for trivial stuff like this.
> 
> Maybe shell constructs like this would suffice?
> 
>   { echo error | tee >(cat >&2); }

Or this is simpler:

  echo error | tee /dev/stderr

cheers,
Pádraig.




This bug report was last modified 6 years and 270 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.