[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

trap handler scope wrong?

From: Phillip Susi
Subject: trap handler scope wrong?
Date: Sat, 04 Mar 2006 18:31:47 -0500
User-agent: Mail/News 1.5 (X11/20060213)

I ran into something weird the other day, but I'm not sure if it's a bug or not 
since I'm a bit new to bash shell scripting.  Basically I have a script that 
has structure like this:

set -e
trap "cat $LOGFILE" ERR
} > $LOGFILE 2>&1

If an error happens inside the {} block, it looks like the ERR trap handler is called inside the {} context, so it's stdout is redirected to the log file. I had expected it to be called in the same scope it was defined in so that it's stdout would not be redirected. Is this a bug, or expected behavior? If it is expected, can anyone suggest a way to do what I'm trying to? The reason for this structure was to redirect verbose output to a log file which would normally be deleted from the EXIT trap handler, but if anything goes wrong, the ERR handler is to cat the full log file so I can see exactly what went wrong.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]