在我的 shell 脚本中,我得到了这些行:
rm tempfl.txt
rm tempfl2.txt
如果这些不存在,我会收到错误消息:
rm: tempfl2.txt: No such file or directory
rm: tempfl.txt: No such file or directory
有没有办法只抑制这些消息,即使它们并不总是出现,因为文件可能存在?
最佳答案
您有两个选择:
禁止 rm
警告
$ rm tempfl.txt 2> /dev/null
将脚本输出重定向到 /dev/null
$ ./myscript.sh 2> /dev/null
后者的缺点是会丢失脚本生成的所有其他警告消息。
关于shell - 如何抑制 shell 脚本错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15678796/