Re: trap and exit status

From: Juergen Heck (btd.heck_at_t-online.de)
Date: 07/30/03


Date: Wed, 30 Jul 2003 20:15:27 +0200


Ben wrote:
>
> Juergen Heck wrote:
> > trap 'exitfunc $? ' EXIT
> > trap 'sigintfunc $? ' INT
> > trap ...
>
> Should always return 0.

Example:
$ cat show1.ksh
#! /bin/ksh
function exitfunc { echo retcode of last cmd: $1 ; }
trap 'exitfunc $? ' EXIT
false
$ ./show2.ksh
retcode of last cmd: 1

$ cat show2.ksh
#! /bin/ksh
function exitfunc { echo retcode of last cmd: $1 ; }
trap 'exitfunc $? ' EXIT
true
$ ./show2.ksh
retcode of last cmd: 0

Regards
Juergen



Relevant Pages

  • Re: trap and exit status
    ... >$ cat show1.ksh ... >retcode of last cmd: 1 ... Program usually do not terminate with true or false, but exit. ...
    (comp.unix.shell)
  • Re: [PATCH #2] Re: SATA and 2.6.0-test9
    ... The 4th port seems to ... ata_bus_reset: EXIT ... ata_exec_command_mmio: ata1: cmd 0xEC ... ata_device_add: ata4: probe-wait begin ...
    (Linux-Kernel)
  • Re: beginTrans without commitTrans or rollbackTrans
    ... A better way to deal with this is to raise your own error and exit via the ... instead of using Exit Function: ... > what if there's beginTrans without commitTrans or rollbackTrans? ... > Dim cmd As ADODB.Command ...
    (microsoft.public.vb.general.discussion)
  • Re: Seeding Randomization on CMD (WinXP Pro)
    ... However since my script takes exactly the ... >>real random number on CMD? ... > Returns an exit code of a pseudo-random number based on ... Thanks Mark! ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: check runing process with ps & grep
    ... This cmd has a problem due to that forked grep process sometime being ... But the way I read what you wrote, I think you are trying to get the exit ...
    (comp.unix.shell)