Reputation: 568
I am using 2>&2 in my script and expect stderr to not be displayed on terminal and be redirected to /dev/fd/ instead. Errors are still displayed on terminal. Is there is something wrong with my understanding? Thanks.
Edit: I wanted to redirect standard error to logfile as well as on terminal.
This works fine(Discovered via hit and trial)
exec 2> >(while read -r line; do printf '%s %s\n' "$(date --rfc-3339=seconds)" "$line" | tee -a $LOG_FILE; done >&2)
But this doesn't
exec 2> >(while read -r line; do printf '%s %s\n' "$(date --rfc-3339=seconds)" "$line" | tee -a $LOG_FILE; done)
I wanted to understand what >&2 did that command 1 works but command 2 doesn't
Upvotes: 0
Views: 83
Reputation: 15232
No, it doesn't make sense.
With 2>&2
you redirect the file descriptor 2 (stderr) to the resource that is associated with file descriptor 2. So, you don't change anything, you just redirect stderr to where it is already directed to.
The default resource for stderr is the terminal, so that's why the stderr output is displayed still on the terminal.
Upvotes: 1