tcsh 和其他 shell 之间的 stderr 重定向不一致

Sil*_*eth 9 tcsh io-redirection stderr

我在 tcsh 中遇到重定向问题。

考虑以下命令:vi --versionvi --xxx。让我们假设这是在vi支持该--version选项的机器上。该选项--xxx无效,因此vim应通过stderr.

根据这个推理,2> /dev/null与这两个命令一起使用应该给出有效情况的输出,而无效情况则没有输出。

就是我在 bash、zsh、ksh 和 dash 中看到的。

$ vi --xxx 2> /dev/null
$ vi --version 2> /dev/null
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 20 2014 16:09:17)
...
Run Code Online (Sandbox Code Playgroud)

但是,当我在 tcsh 中尝试此操作时,在这两种情况下没有输出

$ vi --xxx 2> /dev/null
$ vi --version 2> /dev/null
(there is no output here)
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?我重定向stderr错误吗?

这是输出tcsh --version

tcsh 6.18.01 (Astron) 2012-02-14 (i686-intel-linux) options wide,nls,dl,al,kan,rh,nd,color,filec
Run Code Online (Sandbox Code Playgroud)

Cel*_*ada 14

这种不一致实际上是csh 编程被认为有害的原因列表中的第一个原因。

或者,如果您只想扔掉 stderr 而不要理会 stdout 呢?操作很简单吧?

cmd 2>/dev/null
Run Code Online (Sandbox Code Playgroud)

在 Bourne shell 中工作。在csh中,你只能做这样一个可怜的尝试:

(cmd > /dev/tty) >& /dev/null
Run Code Online (Sandbox Code Playgroud)

但是谁说标准输出是我的 tty?所以这是错误的。这个简单的操作不能在 csh 中完成。

  • 或者`sh -c 'cmd 2> /dev/null'` (6认同)