How do I conditionally redirect the output of a command to /dev/null?

前端 未结 4 1590
不思量自难忘°
不思量自难忘° 2020-12-31 04:51

I have a script. I would like to give this script a quiet mode and a verbose mode.

This is the equivalent of:

if $verbose
then
  redirect=\"> /dev         


        
4条回答
  •  Happy的楠姐
    2020-12-31 05:18

    Got the idea from another question:

    #!/bin/sh
    
    if [ $SILENT ]; then
        exec &>/dev/null
    fi
    
    echo "Silence here."
    

提交回复
热议问题