In scripts, errors are usually sent to file descriptor 2 with &2
, ie:
echo "error" >&2
Sometimes /dev/stderr
is used instead:
echo "error" > /dev/stderr
Looking at /dev/stderr
, I see that it is only a symlink to /proc/self/fd/2
, which in turn is a symlink to /dev/pts/5
(on my current terminal).
Seems little bit over complicated. Is there some logic behind that ?
Is using /dev/stderr
and &2
equivalent ?
Is any of those preferred over the other ?
echo "error" >2
creates a file with name2
and contenterror
. – Cyrus Apr 03 '16 at 16:42>2
, or>&2
? – Jeff Schaller Apr 03 '16 at 17:37