Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

shell scripting

Name: Anonymous 2010-01-26 5:45

sup

im using 'exit 1' in a 'case' construct.
im also using 'trap' to delete some tmp data.
the problem is, that 'trap' isn't triggered by 'exit 1'. trap works though if i send ctrl-z.
why is that?
btw, my trap:
trap "rm $TMP; exit 1" 1 2 15

Name: Anonymous 2010-01-26 23:02

>>1
Why would trap trap exit 1? Trap traps signals. Exit does not send a signal; it just exits.

Better way is to define an error handler.

function cleanup {
  rm -f $TMP
}
function errorexit {
  cleanup
  exit 1
}
trap errorexit SIGHUP SIGINT SIGTERM


Now call errorexit instead of exit 1.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List