trap handler scope wrong?

2006-03-10 Thread Phillip Susi
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 lo

Re: trap handler scope wrong?

2006-03-07 Thread Paul Jarc
Phillip Susi <[EMAIL PROTECTED]> wrote: > Chet Ramey wrote: >> That's about right, but you need >&3 in the trap command. > > I did have > &3 in the trap command, see? You have "> &3". You need ">&3", without a space. > I'm a bit worried though about hard coding the fd 3. Is there a way > to get

Re: trap handler scope wrong?

2006-03-07 Thread Phillip Susi
Chet Ramey wrote: trap "cat $LOG > &3" ERR { foo bar } 3>&1 > /dev/null That's about right, but you need >&3 in the trap command. I did have > &3 in the trap command, see? I'm a bit worried though about hard coding the fd 3. Is there a way to get the next available fd number and save it

Re: trap handler scope wrong?

2006-03-07 Thread Chet Ramey
Phillip Susi wrote: > Does redirecting to /dev/tty work if the original stdout of the shell > was NOT a tty? This script runs as a cron job so it has no tty. Probably won't work to use /dev/tty in that case. > Also is there a better way to save the original stdout and switch back > to it than th

Re: trap handler scope wrong?

2006-03-07 Thread Chet Ramey
Phillip Susi wrote: > Chet Ramey wrote: >>> trap "cat $LOG > &3" ERR >>> { >>> foo >>> bar >>> } 3>&1 > /dev/null >> >> That's about right, but you need >&3 in the trap command. > > I did have > &3 in the trap command, see? There can't be a space between `>' and `&'. That's a syntax error. >

Re: trap handler scope wrong?

2006-03-06 Thread Chet Ramey
Phillip Susi wrote: > 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

Re: trap handler scope wrong?

2006-03-05 Thread Phillip Susi
Does redirecting to /dev/tty work if the original stdout of the shell was NOT a tty? This script runs as a cron job so it has no tty. Also is there a better way to save the original stdout and switch back to it than this: trap "cat $LOG > &3" ERR { foo bar } 3>&1 > /dev/null Chet Ramey w