Sil*_*eth 9 tcsh io-redirection stderr
我在 tcsh 中遇到重定向问题。
考虑以下命令:vi --version
和vi --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 呢?操作很简单吧?
Run Code Online (Sandbox Code Playgroud)cmd 2>/dev/null
在 Bourne shell 中工作。在csh中,你只能做这样一个可怜的尝试:
Run Code Online (Sandbox Code Playgroud)(cmd > /dev/tty) >& /dev/null
但是谁说标准输出是我的 tty?所以这是错误的。这个简单的操作不能在 csh 中完成。
归档时间: |
|
查看次数: |
10462 次 |
最近记录: |