我试图将stderr重定向到stdout,然后再重定向pipe,但我认为这里缺少一些基本的东西。
要管道化的命令和输出:
$ apt-cache show contractor
N: Can't select versions from package 'contractor' as it is purely virtual
N: No packages foundGrep不起作用-必须输出到stderr:
$ apt-cache show contractor |grep virtual好的,让我们将stderr重定向到stdout:
$ apt-cache show contractor 2>&1 |grep virtualNope这不工作,为什么?
确认命令使用的是哪个文件描述符:
$ 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证实它在使用stderr。
和重定向的顺序有关吗?
$ apt-cache show contractor |cat 2>&1不是
$ apt-cache show contractor 2>&1 |cat 2>&1不是
如何将stderr重定向到stdout,然后重定向pipe?
发布于 2020-10-29 17:35:16
这是因为当apt-cache的stdout不是tty时,它将变得“安静”,而不会打印这些行。
您可以通过将其“安静”设置为0来覆盖该确定:
$ apt-cache -q=0 show contractor 2>&1 | grep virtual
N: Can't select versions from package 'contractor' as it is purely virtualhttps://unix.stackexchange.com/questions/617073
复制相似问题