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 error message:
$ ls *.zip
ls: cannot access '*.zip': No such file or directory
Is there an option to suppress such error messages? I want to use this command in a bash script but I want to hide all errors.
Most Unix commands, including ls
, will write regular output to stdout and error messages to stderr so you can use bash redirection to throw away the error messages while leaving the regular output in place:
ls *.zip 2> /dev/null
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments