Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

TRAPEXIT doesn't get executed



I'm trying to find the right idiom to make sure some cleanup code gets
executed no matter how the script exits.

When I run this script:
  
---------------------------------------------------------
#!/usr/bin/zsh
  
set -x
  
function TRAPEXIT {
    print "executed TRAPEXIT"
}
sleep 10
---------------------------------------------------------
  
And hit Ctrl-C while "sleep 10" is executing, the TRAPEXIT isn't
executed.  But when I run this script:
  
---------------------------------------------------------
#!/usr/bin/zsh
  
set -x

function TRAPEXIT {
    print "executed TRAPEXIT"
}
function TRAPINT {
    print "executed TRAPINT"
}
sleep 10
---------------------------------------------------------

And hit Ctrl-C, both TRAPINT and TRAPEXIT get executed.  Is this
explained anywhere?  The behavior is the same under 3.0 and 3.1, so I
imagine this has been covered before.

-- 
matt



Messages sorted by: Reverse Date, Date, Thread, Author