How to hide command output in Bash

后端 未结 7 1395
天涯浪人
天涯浪人 2020-12-02 05:42

I want to make my Bash scripts more elegant for the end user. How do I hide the output when Bash is executing commands?

For example, when Bash executes



        
相关标签:
7条回答
  • 2020-12-02 06:18

    You can redirect the output to /dev/null. For more info regarding /dev/null read this link.

    You can hide the output of a comand in the following ways :

    echo -n "Installing nano ......"; yum install nano > /dev/null; echo " done."; 
    

    Redirect the standard output to /dev/null, but not the standard error. This will show the errors occurring during the installation, for example if yum cannot find a package.

    echo -n "Installing nano ......"; yum install nano &> /dev/null; echo " done.";
    

    While this code will not show anything in the terminal since both standard error and standard output are redirected and thus nullified to /dev/null.

    0 讨论(0)
提交回复
热议问题