抑制Shell脚本错误消息 [英] suppress shell script error messages

查看:305
本文介绍了抑制Shell脚本错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的shell脚本中,我得到了以下几行:

In my shell script I got these lines:

rm tempfl.txt
rm tempfl2.txt

如果这些不存在,我会收到错误消息:

If these do not exist I get the error messages:

rm: tempfl2.txt: No such file or directory
rm: tempfl.txt: No such file or directory

有没有办法仅抑制这些消息,即使它们并不总是出现(因为文件可能存在)?

Is there a way to only suppress these messages even though they do not always appear, as the files might exist?

推荐答案

您有两个选择:

禁止显示rm警告

Suppress rm warnings

$ rm tempfl.txt 2> /dev/null

将脚本输出重定向到/dev/null

Redirect script output to /dev/null

$ ./myscript.sh 2> /dev/null

后者的缺点是会丢失脚本生成的所有其他警告消息.

The latter has a drawback of missing all other warning messages produced by your script.

这篇关于抑制Shell脚本错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆