禁止 bash 中的警告输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18217753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Suppress warning output in bash
提问by user433342
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
I tried adding 2>/dev/null, &>/dev/null, etc, nothing seemed to suppress the warnings.
我尝试添加 2>/dev/null、&>/dev/null 等,似乎没有任何东西可以抑制警告。
回答by Damian T.
mysql_tzinfo_to_sql /usr/share/zoneinfo 2>/dev/null | mysql -u root mysql
The command that is producing the error output to STDERR is the first command, not the second one. Put the STDERR redirection before the pipe, and this should fix your problem.
产生错误输出到 STDERR 的命令是第一个命令,而不是第二个。将 STDERR 重定向放在管道之前,这应该可以解决您的问题。
回答by Gilles Quenot
Better give your exact code attempt and warnings in your original post, but if you try this one :
最好在原始帖子中给出确切的代码尝试和警告,但如果您尝试这个:
{ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql; } 2>/dev/null
or
或者
mysql_tzinfo_to_sql 2>/dev/null /usr/share/zoneinfo |
mysql -u root mysql 2>/dev/null
that should work.
那应该工作。
回答by konsolebox
Try enclosing it on a subshell
尝试将其包含在子外壳中
( mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql ) &>/dev/null