How to silence output in a Bash script?

后端 未结 9 2059
离开以前
离开以前 2020-11-29 17:15

I have a program that outputs to stdout and would like to silence that output in a Bash script while piping to a file.

For example, running the program will output:<

9条回答
  •  臣服心动
    2020-11-29 17:41

    If it outputs to stderr as well you'll want to silence that. You can do that by redirecting file descriptor 2:

    # Send stdout to out.log, stderr to err.log
    myprogram > out.log 2> err.log
    
    # Send both stdout and stderr to out.log
    myprogram &> out.log      # New bash syntax
    myprogram > out.log 2>&1  # Older sh syntax
    
    # Log output, hide errors.
    myprogram > out.log 2> /dev/null
    

提交回复
热议问题