在Bash中将标准错误重定向为null-“日期:无效的日期“从不”” [英] Redirect standard error to null in Bash - "date: invalid date `Never'"
问题描述
我需要将以下错误重定向到/ dev / null文件。
I require the following error to be redirected to the /dev/null file.
a=$(date -d "Never" +%s) > /dev/null 2>&1
date: invalid date `Never'
输入到date命令的date实际上是通过有时会获得从不的变量传递的。在这种情况下,将显示上述消息中所示的错误,需要将其消除。
The date that is input to the date command is actually being passed through a variable which sometimes acquires "Never". In such a case, an error is shown as shown in the above message which is required to be suppressed.
是否存在另一种将输出重定向到空文件的方法?
Is there another method to redirect the output to the null file?
推荐答案
您当前正在做什么:将分配的输出重定向到 / dev / null
。
What you are doing currently: redirecting the output of the assignment to /dev/null
.
您想做什么:重定向<$ c的错误输出 $ c> date 命令到 / dev / null
What you want to do: redirecting the error output of the date
command to /dev/null
a=$(date -d "Never" +%s 2>/dev/null)
这篇关于在Bash中将标准错误重定向为null-“日期:无效的日期“从不””的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!