Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16528

Re: bash 1-liner or function to tee to STDERR in middle of pipe?

From Lawrence Velázquez <vq@larryv.me>
Newsgroups gnu.bash.bug
Subject Re: bash 1-liner or function to tee to STDERR in middle of pipe?
Date 2020-07-03 14:03 -0400
Message-ID <mailman.896.1593799409.2574.bug-bash@gnu.org> (permalink)
References <202007031432.063EWIhD3254754@epjdn.zq3q.org> <936693AC-5B43-4A84-A993-BCA6142AA381@larryv.me>

Show all headers | View raw


> On Jul 3, 2020, at 10:32 AM, bug-bash@trodman.com wrote:
> 
> This does what I want: 
> 
> --8<---------------cut here---------------start------------->8--- 
> _tee_stderr () 
> { 
>     <<'____eohd'
>    SYNOPSIS
> 
>        ourname
> 
>    DESCRIPTION
> 
>        Use in a pipe. Leaks STDIN to STDERR. Passes STDIN to STDOUT unchanged.
> 
>    EXAMPLE
> 
>        $ seq 5 |_tee_stderr |tail -2 > /tmp/bar ; echo;cat  /tmp/bar
>        1
>        2
>        3
>        4
>        5
> 
>        4
>        5
> 
> ____eohd
> 
>    ( tmpf=$( mktemp ~/tmp/$FUNCNAME.XXX );
>    cat > $tmpf;
>    cat $tmpf 1>&2;
>    cat $tmpf;
>    rm -f $tmpf );
>    return;
> }
> --8<---------------cut here---------------end--------------->8--- 
> 
> What is better/cleaner?

An ad hoc function that forcibly writes the entire input to disk
and doesn't even clean up after itself if it's interrupted, versus
a widely known, standard tool that's just as easy to use?

What's wrong with `foo | tee /dev/stderr | bar`?

vq

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: bash 1-liner or function to tee to STDERR in middle of pipe? Lawrence Velázquez <vq@larryv.me> - 2020-07-03 14:03 -0400

csiph-web