I'm trying to redirect stderr
to stdout
and then pipe
it but I think I'm missing something basic here.
The command and output to be piped:
$ apt-cache show contractor
N: Can't select versions from package 'contractor' as it is purely virtual
N: No packages found
Grep does not work - must be outputting to stderr
:
$ apt-cache show contractor |grep virtual
OK Let's redirect stderr
to stdout
:
$ apt-cache show contractor 2>&1 |grep virtual
Nope this does not work, why?
Confirm which file descriptor the command is using:
$ apt-cache show contractor 1>t ;cat t
$ apt-cache show contractor 2>t ;cat t
N: Can't select versions from package 'contractor' as it is purely virtual
N: No packages found
Confirmed it's using stderr
.
Something to do with ordering of redirects?
$ apt-cache show contractor |cat 2>&1
Nope
$ apt-cache show contractor 2>&1 |cat 2>&1
Nope
How to redirect stderr
to stdout
then pipe
?