Just trying to redirect stout to stderr. But I'm a little confused about these two commands.
echo test 2>/dev/null 1>&2
echo test 1>&2 2>/dev/null
I don't understand why the second one doesn't work properly.
Just trying to redirect stout to stderr. But I'm a little confused about these two commands.
echo test 2>/dev/null 1>&2
echo test 1>&2 2>/dev/null
I don't understand why the second one doesn't work properly.
>/dev/null 2>&1
– Kusalananda Oct 10 '19 at 14:59echo test 1>&2 2>/dev/null
working a little likeecho test 1>&2;echo test 2>/dev/null
– bob dylan Oct 10 '19 at 15:012>/dev/null 1>&2
iserr:=/dev/null; out:=err
, and1>&2 2>/dev/null
isout:=err; err:=/dev/null
. After the 1st, bothout
anderr
will be/dev/null
, and after the 2nd,err
will be/dev/null
, butout
will be whatevererr
was before the operation (eg. a handle to your tty) – Oct 10 '19 at 16:54echo test 1>&2;echo test 2>/dev/null
is the same asecho test >&2; echo test
, and unlike your 1st example (which does not print anything at all), will printtest
twice, once to stdout and once to stderr ;-) – Oct 10 '19 at 16:59