Subject: Re: bashism for ksh
To: None <tech-userlevel@NetBSD.org>
From: Peter Bex <Peter.Bex@xs4all.nl>
List: tech-userlevel
Date: 09/27/2007 09:22:14
--NqSa+Xr3J/G6Hhls
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Sep 26, 2007 at 09:09:04PM +0000, Thorsten Glaser wrote:
> Aleksey Cheusov dixit:
>=20
> >7 ~>ret5 | true | ret5
> >5 0 5 ~>true | false | ret7
> >0 1 7 ~>false | false
>=20
> Ah okay. This is not easily possible because the parts of the pipe
> are run in subshells. I guess that means deep code changes.

Afaik the subshell returns the exit status of the last command it
runs.  Thus you can just reap the exit status of the subshell with
wait(2).

> If you offer a patch, documentation (patch for manpage), and a
> list what other shells have this functionality and how it works
> in these, I might consider including it though.

In zsh, I have this neat expression as part of my PROMPT variable:
%B%(?0..(%?%))

It's unreadable, but it means:
"print in bold the following:
if the previous command's exit status was 0, display nothing (empty
string between the first and second dot), if it was nonzero, display
the exit status between brackets."

So whenever a command terminated with an error, it alerts me by
changing my prompt from
sjamaan@machine$
to
sjamaan@machine(1)$
with the (1) part in bold.

It's great because it only draws attention to itself when something out
of the ordinary is happening, and keeps the prompt clean otherwise.

Cheers,
Peter
--=20
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
							-- Donald Knuth

--NqSa+Xr3J/G6Hhls
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (NetBSD)

iQEVAwUBRvtaJtOrBFwYag3gAQJIlwf/bD2rt2mRoa6+FBMe6HpiUOWODda8zB2Z
Dsn9Hrs/SBdBBUlCXmzzik1/osM/bs3/3MplzNA6ZaoupwbxQDl7O1z//M2x1Kia
fauuaEkFyZk5OSf2cLl0H25z2J8zbUeClmGQOEQ7MbnIETzmDMuYe7rI3BgeXwQM
tP0PDLeQlXGj/5vXf+kys+iLzB0RpK8UPzvb/qDDJma23CMZQTGfW8UJagMPgTOu
4lchr46TMC12xuGgyWSQow0ERBi+CYpnDMrgoPuBDnQMadJ6m1+tQZ654p66/+7Q
gT3ZWwVZQAf9V0f2r+xAvYTfac1ufae3ZY6QEw5/U9MwpRMaHiJWnQ==
=fy4e
-----END PGP SIGNATURE-----

--NqSa+Xr3J/G6Hhls--