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?

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
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 Fri, 3 Jul 2020 14:03:20 -0400
Lines 50
Approved bug-bash@gnu.org
Message-ID <mailman.896.1593799409.2574.bug-bash@gnu.org> (permalink)
References <202007031432.063EWIhD3254754@epjdn.zq3q.org> <936693AC-5B43-4A84-A993-BCA6142AA381@larryv.me>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0 (Mac OS X Mail 12.4 \(3445.104.14\))
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding quoted-printable
X-Trace usenet.stanford.edu 1593799410 3172 209.51.188.17 (3 Jul 2020 18:03:30 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bug-bash@gnu.org
To bug-bash@trodman.com
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=larryv.me; h= content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s=fm3; bh=B w/yS1zgzQEqM+Z2MC4g9PtG2MiF0+Egmq1Z25T8+Zk=; b=qd1/xAZGVnN9jq9pT KC8xIEXxQk8MGQNs128TwT/+SNitof/XRmAi63xsvzium6Dn8o2UZ2zckdfCNGE+ o68FFXiEZ3OFWwcTOI76mHeCdXddrIeU+yMCvluu+ep5nfPnu9mzLtL9S4noYYz0 RGfDj267jhjRj4iPAePE51NkDJAP98ftqv1tW40d6v2wQsboN37M0fOvk6f9EFPp PV6zVa8TUnaMc/sZoWdbmeolxUE/M9+u9OA4Hzfd0qaaz80y2f3eipONHOkq+1YF 1n4kvVrjOWzy7Snz7+rpuc8N9p+OY73BlhX1FSCDYwA3ng3n3NsRZ6IIHUcGTvie i8/1w==
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=Bw/yS1zgzQEqM+Z2MC4g9PtG2MiF0+Egmq1Z25T8+ Zk=; b=THA9Y6jp6c9UYI963UhK7UTuTBMZXgIlbjJQkVcZGKOfWjhfwjJ69IsgA wPXpUR6AWs7+0whKR7yxfBoW5klMAoL3QeGswSAwYsbQQ+Ij28HA/0nUboQtecPk xV4B1Kli7bMYbl/NEhawrRLDIzzfoaYCip04/Y23CJF5k2pOenW75hznrp5+LnB5 JOPqxPF/H5iBjQdBqoF7HZkmd3I44Vf1DUL67ZkId/98hsg1Tv2LO5NgWwCvb+2F LNqhjl2DxMi3HIOAgsEuULaNaTppkX66s4BmgaPUSQULhbyqMyIwy+5baO1SMDrf 4kp6guLM10raREUYRn96Ai/VzmFnQ==
X-ME-Sender <xms:6XL_Xs03zLJ-9oz_LZZmR8nous5xwUl2Q-qRFrx2Dz_RPTDFiuew4g>
X-ME-Proxy-Cause gggruggvucftvghtrhhoucdtuddrgeduiedrtdeigdduvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpegtggfuhfgjfffgkfhfvffosehtqh hmtdhhtddvnecuhfhrohhmpefnrgifrhgvnhgtvggpgggvlhojiihquhgviicuoehvqhes lhgrrhhrhihvrdhmvgeqnecuggftrfgrthhtvghrnhepgeetheejueekgeffhefhjeevje eiheegvdeugeektdegffejhfehgeetgfejledvnecukfhppedutddtrdduvddrudekgedr vdegieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hvqheslhgrrhhrhihvrdhmvg
X-ME-Proxy <xmx:6XL_XnEMCBoJtrtiA9yHj1gCE3QDhzl-U0vY779k1-WLIYTdRO3i5A> <xmx:6XL_Xk4qJ77uURA0o-tkpEzdDYNQoOZ31mMKxr1qjPwglHloIlECew> <xmx:6XL_Xl2Deg_slEcVKHKMkpjKL4nlfrkc1qCBHWgXa_ezygRsjRRO9A> <xmx:6XL_XjTv7NIfFAvQdmDQljZZnbVLanC0pSeLNxq8hp_iGU4OuW93XQ>
In-Reply-To <202007031432.063EWIhD3254754@epjdn.zq3q.org>
X-Mailer Apple Mail (2.3445.104.14)
Received-SPF pass client-ip=64.147.123.24; envelope-from=vq@larryv.me; helo=wout1-smtp.messagingengine.com
X-detected-operating-system by eggs.gnu.org: First seen = 2020/07/03 14:03:22
X-ACL-Warn Detected OS = Linux 2.2.x-3.x [generic] [fuzzy]
X-Spam_score_int -27
X-Spam_score -2.8
X-Spam_bar --
X-Spam_report (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN
X-Spam_action no action
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <936693AC-5B43-4A84-A993-BCA6142AA381@larryv.me>
X-Mailman-Original-References <202007031432.063EWIhD3254754@epjdn.zq3q.org>
Xref csiph.com gnu.bash.bug:16528

Show key headers only | 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