[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash 1-liner or function to tee to STDERR in middle of pipe?
From: |
Lawrence Velázquez |
Subject: |
Re: bash 1-liner or function to tee to STDERR in middle of pipe? |
Date: |
Fri, 3 Jul 2020 14:03:20 -0400 |
> 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