error processing in borne

Tom Christiansen tchrist at convex.COM
Fri Apr 26 02:02:35 AEST 1991


>From the keyboard of afsihrs at cidsv01.cid.aes.doe.CA ():
:
:  WE ARE IN THE PROCESS OF CONVERTING TO UNIX AND HAVE COME UP
:AGAINST A PROBLEM WITH ERROR PROCESSING. THE FOLLOWING IS AN 
:EXAMPLE OF OUR OLD JCL:
:
:  COMMAND
:  COMMAND
:  COMMAND
:  EXIT
:  ERROR-COMMAND
:  ERROR-COMMAND
:  IN THE ABOVE IF THE JOB WORKED PROPERLY IT ENDED AT EXIT,WHILE
:IF ANY COMMAND ABORTED, IT WOULD IMMEDIATELY GO TO THE EXIT AND
:PROCESS THE ERROR-COMMANDS. IS THERE SOME METHOD EQUIVALENT TO
:TRAP THAT WE CAN USE TO EXIT ON ANY ERRORS? WE ALSO DON'T WANT 
:TO HAVE TO CHECK AFTER EVERY COMMAND.

well, the first problem you need to solve is to get your caps lock
keys fixed. :-)

you can use something like this:

    #!/bin/sh -e

    trap 'special error commands' 0
	some commands that might fail
	triggering the exit due to -e,
	and then trigger the onexit trap
    trap 0 # clear on exit trap
    exit 0 # and leave

--tom



More information about the Comp.unix.shell mailing list