Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Rusty Bird Newsgroups: gnu.bash.bug Subject: Re: 'foo > >(bar)' doesn't set $! for external foo not invoked via 'command' Date: Mon, 20 Jul 2020 10:21:36 +0000 Lines: 73 Approved: bug-bash@gnu.org Message-ID: References: <20200719204836.GA1184@mutt> <20200720102136.GA1147@mutt> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ikeVEW9yuYc//A+q" X-Trace: usenet.stanford.edu 1595240509 23735 209.51.188.17 (20 Jul 2020 10:21:49 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: =?utf-8?B?T8SfdXo=?= Envelope-to: bug-bash@gnu.org X-EA-Auth: 0MmQTGd+EdomoiTh+Lr5dOIFtse7Mdh5CNRJddmLyblE2bZgRsDO8cRJ7A2+PB1QjlrG4O7oxJ4UOoOdxmdGwVWpeTvIzRXRkn8MkaOaiv0= Mail-Followup-To: =?utf-8?B?T8SfdXo=?= , bug-bash@gnu.org Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=213.182.54.6; envelope-from=rustybird@net-c.com; helo=relay-1.mailobj.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/20 06:21:42 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20200720102136.GA1147@mutt> X-Mailman-Original-References: <20200719204836.GA1184@mutt> Xref: csiph.com gnu.bash.bug:16588 --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable O=C4=9Fuz: > > For context - I'm filtering a program's stdout and stderr > > (separately), requiring successful exit statuses for the program and > > both filters: > > > > set -u -o pipefail > > { program 2> >(stderr_filter >&2) && wait $!; } | stdout_filter= && > > ... > Not sure if process substitution is really necessary here, >=20 > set -u -o pipefail > { program 2>&3 | stdout_filter; } 3>&1 | stderr_filter && ... >=20 > does the same thing. That one filters program's stdout twice - first through stdout_filter and then through stderr_filter - with program's stdout and stderr both finally arriving at stdout. But tweaked like this, it seems to cover all the bases: set -u -o pipefail { program 2>&1 >&"$out" {out}>&- | stderr_filter >&2 {out}>&- } {out}>&1 | stdout_filter And it even waits for stderr_filter if program failed. My original snippet neglected that case, otherwise it would have looked more like set -u -o pipefail ( trap 'wait $! || exit $?' EXIT command program 2> >(stderr_filter >&2) ) | stdout_filter which isn't exactly pretty either, even if the bug(?) requiring 'command' is fixed. Rusty --ikeVEW9yuYc//A+q Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQKTBAEBCgB9FiEEhLWbz8YrEp/hsG0ERp149HqvKt8FAl8VcDBfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDg0 QjU5QkNGQzYyQjEyOUZFMUIwNkQwNDQ2OUQ3OEY0N0FBRjJBREYACgkQRp149Hqv Kt9Qtg//Sb/rxk+EuOsKTwnc459gb2CzWCAahkoP9igLFyivC34cCrEDE1dzUr+0 EJv9c+CikmldcjwtJm83DYl3T25Mfq5XYBdEXR0q7jW7Sd07omfCcRDWPS7OxKy4 N+uBGQp0e9aLVkgmYjPUQenzdofOori+vYNiviuGCmrOfq36sqPzuZPN1VhQNIo1 I4hnJI1HYSS4RupBtPDXXxIz1jXOtBPVQ9nAyBghpgMJR5gMqew13GIQe46jH1aR Kn3DlfBNRWeN6hfzTYi6H6PA0h+/oz59wnw8JZrfQj28AqLu5A3UWbUFA+x0hx9W Zqoza8weFuamreNbKTwiqk8U/b+kCKUXqzEkK73bujxPeN+ekulJOI4AGZY28aX6 a+iurUEeDF3u2nmFXnqU807JRaDPr99+N/BnVyOy6BwqVlSffTcuoDkgOwfrf33f fPdjqUu5qRJiWLo+/HvjjAfg2XKVjMPKeG29CvLHVCtzOy31BGESYuCByRrzvH6f ctnjgSvTIFpME3GOig0Wtj4BwbvZEGW7guPsqap66yJzX/YISkvOKndXwaGqFEa7 derIL6MaxT7GotLGM8Ff76bFjMK0PjaDnubRPQEj/SSOt5nz6jhy7rQ3simgpbfx oBb9GRy6g8eCdTEcspJjNEa3StO5rR0UdJ+ZBFuC24EoghMChMI= =p9q+ -----END PGP SIGNATURE----- --ikeVEW9yuYc//A+q--