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
{
 foo
 bar
 baz
} > $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.


_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to