← 返回博客列表
发布于 2023.11.29 15:37:01 · 约 88 字

shell-不要error输出

再执行一些操作时,我知道它有可能报错,但我不想要它输出,就这么做

rm notexistfile 2>/dev/null

这里的例子是,删除一个不存在的文件。使用输出重定向来解决问题。


其他的输出重定向有

  • > myfile 和 1> myfile 重定向stdout到myfile
  • 2> myfile 重定向stderr到myfile
  • &> myfile和 > myfile 2>&1 重定向 stdout和stderr到myfile