I do not think that the error error handler receives any information about the exact error that made it work. You can get the exit code from the failed command, but by the time the trap starts, you do not know which command was not executed.
You can try writing a simple C program to get the latest system error using perror or some of these.
... Update: it does not work; in retrospect, for obvious reasons. I will leave it here for future generations. / -:
vnix$ cat perror.c #include <stdio.h> #include <errno.h> int main (int argc, char **argv) { perror(""); } vnix$ gcc perror.c vnix$ touch /fnord touch: cannot touch `/fnord': Permission denied vnix$ ./a.out Success
source share