Inside the function call (which is inside the script)
a printf needs to send stderr to both the tty and the log.
Would this be the way to do it?
printf "%s %s\n" "$RESULT" "$LOCATION" 2>&1 |tee "$log"
This will send the message to the log and stdout, and you said stdout
goes to a file, so it will go to the log and the file, not the terminal.
Try this:
printf ... | tee "$log" >/dev/tty
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
> This will send the message to the log and stdout, and you said stdout
> goes to a file, so it will go to the log and the file, not the terminal.
> Try this:
>
> printf ... | tee "$log" >/dev/tty
Or perhaps
printf ... | tee /dev/tty
which will send it to STDOUT.
So the command shouldn't contain the 2>&1 ?
I'm a little confused. What tells stderr
to go somewhere else ... in this case
to the logfile and the tty?
And in the OP you asked:
>>>> Would this be the way to do it?
>>>>
>>>> printf "%s %s\n" "$RESULT" "$LOCATION" 2>&1 |tee "$log"
This would not send your data to the tty but to stdout (which might be
redirected in the outer scope and never hit the tty), so rather use an
additional redirection of stdout to /dev/tty as proposed upthread.
And yes, you need to redirect stderr as well - that was your original
question -, e.g. as you've done, by assigning stderr to the same channel
as stdout. But mind that this way you have no distinction of those two
channels (stdout and stderr) any more, which might be okay or not in
your context. If you want to keep the two channels separated in the
outer scope you have to do some severe (quite complex) i/o descriptor
manipulation.
Janis
Early in the script you should do:
exec 2> "$log"
This tells stderr to go to the log file.
Then, when you want to write a message to stderr, you do:
printf ... >&2
and if you want it to go to both stderr and the terminal, write:
printf ... | tee /dev/tty >&2
> printf "%s %s\n" "$RESULT" "$LOCATION" 2>&1 |tee "$log"
What do you expect printf to write to its stderr here?