🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.bash.bug
Article #82

ksh's trap "" ERR

#82
From: composer
Date: Tue, 13 Jun 1989 22:03
53 lines
2226 bytes
|   Date: 13 Jun 89 17:51:14 GMT
|   From: milano!bigtex!james@cs.utexas.edu  (James Van Artsdalen)
|
|   On feature I miss from ksh is 'trap "" ERR'.  For example, my .ksh
|   file has
|
|   trap 'echo "(ERR:$?)"' ERR
|
|   I tried to simulate this in bash with PROMPT_COMMAND, but it didn't
|   work.  Here's an emacs M-x shell script: it starts out in ksh, and
|   then runs bash.
|
|   /tmp> (exit 1)
|   (ERR:1)
|   /tmp> /usr/local/src/dist-bash/bash
|   /tmp> PROMPT_COMMAND='if [ $? -ne 0 ] ; then echo "(ERR:$?)" ; fi'
|   PROMPT_COMMAND='if [ $? -ne 0 ] ; then echo "(ERR:$?)" ; fi'
|   /tmp> 
|
|   /tmp> (exit 1)
|   (exit 1)
|   /tmp> 
|
|   bash doesn't print the error status.  Also note that bash doesn't
|   behave well under emacs, but I assume this is related to previous
|   reported bugs with determining interactive status.

You had the right idea.  The problem (I believe) with your emulation is
that the status ($?) gets reset after the test.  You could set up a
function to do the same thing as follows:

	function ERR () {
	  local err=$?
	  if [ $? -ne 0 ]; then
	    echo "(ERR:err)"
	  fi
	}
 and then set PROMPT_COMMAND=ERR 

That should work.  Actually, there seems to be a problem with the return
status from a subshell not getting returned properly.  Or, is it supposed
to?  Haven't looked into it yet.  But, "(exit 1)" was returning 0.  There 
also may be better methods of doing this, but I was just taking what you 
had already presented.  Enjoy...

|  James R. Van Artsdalen          james@bigtex.cactus.org   "Live Free or Die"
|  Dell Computer Co    9505 Arboretum Blvd Austin TX 78759         512-338-8789

				-jeff

Jeff Kellem
INTERNET: composer@bu-cs.bu.edu  (or composer%bu-cs.bu.edu@bu-it.bu.edu)
UUCP: ...!harvard!bu-cs!composer
Technical Details
Message-ID: <8906132203.AA04470@bucse.bu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!BU-CS.BU.EDU!composer
References: <18026@bigtex.cactus.org>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!BU-CS.BU.EDU!composer
From: composer@BU-CS.BU.EDU
Newsgroups: gnu.bash.bug
Subject: ksh's trap "" ERR
Message-ID: <8906132203.AA04470@bucse.bu.edu>
Date: 13 Jun 89 22:03:16 GMT
References: <18026@bigtex.cactus.org>
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 53