I'm a bit confused by the results I'm seeing with a pipeline to a
group. I was trying to parse a text file in such a way as the first n
lines are passed straight through, and then a sed script is applied to
the rest. I thought I could do that with something like this:
cat file | ( head --lin
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
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
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