如何抑制 shell 命令的错误消息?
例如,如果只有jpg
目录中的文件,正在运行ls *.zip
给出错误消息:
$ ls *.zip
ls: cannot access '*.zip': No such file or directory
是否有一个选项可以抑制此类错误消息?我想在 Bash 脚本中使用此命令,但我想隐藏所有错误。
大多数 Unix 命令,包括ls
,将常规输出写入标准输出 https://en.wikipedia.org/wiki/Standard_streams#Standard_output_.28stdout.29和错误消息标准误 https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr),所以你可以使用Bash 重定向 http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html丢弃错误消息,同时保留常规输出:
ls *.zip 2> /dev/null
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)