PYP*_*YPL 9 linux shell csh tcsh
我正在执行一个将崩溃报告转储到STDERR我必须过滤一些必要信息的程序.问题是,我无法重定向STDERR到STDOUT与PIPE它grep
command 2>&1 >/dev/null | grep "^[^-]" >& /tmp/fl
Run Code Online (Sandbox Code Playgroud)
得到错误: Ambiguous output redirect.
相同的命令在bash终端下工作.我应该改变什么来使它工作?
Fil*_*ves 12
csh在文件重定向方面比bash明显更有限.在csh,您可以重定向stdout与通常的>操作,您可以重定向都stdout和stderr与>&运营商,可以通过管道stdout和stderr与|&运营商,但没有一个统一的操作重定向stderr孤单.
通常的解决办法是在一个子shell来执行命令,重定向stdout在子shell到你想要的任何文件(/dev/null在这种情况下),然后使用|&操作重定向stdout和stderr子壳在接下来的命令主壳.
在你的情况下,这意味着:
( command >/dev/null ) |& grep "^[^-]" >&/tmp/fl
Run Code Online (Sandbox Code Playgroud)
因为stdout被重定向到/dev/null子shell内部,所以|&操作符最终将像2>&1bash一样 - 因为stdout在子shell中被丢弃,所写的stdout任何内容都不会到达管道.
如果您不介意将stdout和stderr混合到您可以使用的管道中
command |& grep "^[^-]" >& /tmp/fl
Run Code Online (Sandbox Code Playgroud)
否则你可以做黑客:
(command >/dev/null) |& grep "^[^-]" >& /tmp/fl
Run Code Online (Sandbox Code Playgroud)
将stdout分隔为null,然后管道stdout和stderr只给stderr作为内容.
| 归档时间: |
|
| 查看次数: |
12732 次 |
| 最近记录: |