Bash - Suppressing output to STDOUT I've written a script for fresh macOS installs that installs Homebrew, Cask, and a bunch of apps I like, along with creating a .vimrc file.  

Thanks to an answer by daniel Azuelos (located here: Best way to check in bash if Command Line Tools are installed?), a part of the script checks to see if Xcode command-line-tools are installed.  

When command-line-tools are not installed, this error gets displayed to the user:

xcode-select: error: unable to get active developer directory, use `sudo xcode-select --switch path/to/Xcode.app` to set one (or see `man xcode-select`)


I'm hoping someone can help me suppress this output.

The function that is ran to do command-line-tools check is:

function check_clt() {
    if type xcode-select &gt;&amp;- &amp;&amp; xpath=$( xcode-select --print-path ) &amp;&amp; test -d "${xpath}" &amp;&amp; test -x "${xpath}" ; then
        echo ""
        echo "The required Xcode command-line-tools are already installed! Moving on!"
        sleep 3
    else
        instructions
        sleep 45
        xcode-select --install
    fi
}


I believe I can use 2 &gt; /dev/null to suppress the error, but I'm not sure in the function where should it go?  I've put it before each &amp;&amp; in the if statement, but the error message still appeared.

Using Nimesh's suggestion, I've edited the function:

function check_clt() {
if type xcode-select 2&gt;/dev/null &gt;&amp;- &amp;&amp; xpath=$( xcode-select --print-path ) 2&gt;/dev/null &amp;&amp; test -d "${xpath}" 2&gt;/dev/null &amp;&amp; test -x "${xpath}" 2&gt;/dev/null ; then
    echo ""
    echo "The required Xcode command-line-tools are already installed! Moving on!"
    sleep 3
else
    instructions 2&gt;/dev/null
    sleep 45
    xcode-select --install
fi


}

Running the script still produces the error to the user:

Last login: Tue Sep  4 20:40:13 on ttys000
vimusrs-Mac:~ vimusr$ cd Desktop/
vimusrs-Mac:Desktop vimusr$ chmod +x mai.sh 
vimusrs-Mac:Desktop vimusr$ ./mai.sh 
xcode-select: error: unable to get active developer directory, use `sudo xcode-select --switch path/to/Xcode.app` to set one (or see `man xcode-select`)
Turns out the xpath=( xcode-select --print-path ) line in the if statement of the original function was the problem.  Additionally, once I got the error message suppressed, I noticed there was an unnecessary stdout message, so I decided to suppress that as well.

I was able to suppress the stderror and stdout messages by changing the function to the following:

function check_clt() {
    if type xcode-select &gt;/dev/null 2&gt;&amp;1 &gt;&amp;- &amp;&amp; xcode-select -p &gt;/dev/null 2&gt;&amp;1 &amp;&amp; test -d $(xcode-select -p) &gt;/dev/null 2&gt;&amp;1 &amp;&amp; test -x $(xcode-select -p) &gt;/dev/null 2&gt;&amp;1; then
        echo ""
        echo "The required Xcode command-line-tools are already installed! Moving on!"
        sleep 3
    else
        instructions
        sleep 45
        xcode-select --install
    fi
}