ls -0 > /dev/null 2>&1
-
suppressing the error output (stderr) of the ls -0 command, redirect it to standard output (stdout), writing it to /dev/null thereby immediately discarding it.
This technique is commonly used to tell whether a command exists, which you can use for handling different operating systems, automatically installing packages, downloading files, and most importantly defending your scripts and systems from unexpected exceptions.
function cmd_exists() {
command -v $1 > /dev/null 2>&1
}cmd_exists ls; echo $?
cmd_exists sl; echo $?