[gnu.bash.bug] ksh's trap "" ERR

james@bigtex.cactus.org (James Van Artsdalen) (06/14/89)

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'
PPROMPT_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.
-- 
James R. Van Artsdalen          james@bigtex.cactus.org   "Live Free or Die"
Dell Computer Co    9505 Arboretum Blvd Austin TX 78759         512-338-8789

composer@BU-CS.BU.EDU (06/14/89)

|   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

ray@GIBBS.PHYSICS.PURDUE.EDU (Ray Moody) (06/14/89)

|   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:

    Remember that there is a known bug with $?.  Try applying the fix
I posted earlier.

								Ray