How to suppress error message of a command?

前端 未结 3 1540
梦谈多话
梦谈多话 2020-12-05 06:26

How can I suppress error messages for a shell command?

For example, if there are only jpg files in a directory, running ls *.zip gives an e

3条回答
  •  有刺的猬
    2020-12-05 07:00

    $ ls *.zip 2>/dev/null
    

    will redirect any error messages on stderr to /dev/null (i.e. you won't see them)

    Note the return value (given by $?) will still reflect that an error occurred.

提交回复
热议问题