How to silence output in a Bash script?

后端 未结 9 2065
离开以前
离开以前 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条回答
  •  旧时难觅i
    2020-11-29 17:57

    Redirect stderr to stdout

    This will redirect the stderr (which is descriptor 2) to the file descriptor 1 which is the the stdout.

    2>&1
    

    Redirect stdout to File

    Now when perform this you are redirecting the stdout to the file sample.s

    myprogram > sample.s
    

    Redirect stderr and stdout to File

    Combining the two commands will result in redirecting both stderr and stdout to sample.s

    myprogram > sample.s 2>&1
    

    Redirect stderr and stdout to /dev/null

    Redirect to /dev/null if you want to completely silent your application.

    myprogram >/dev/null 2>&1
    

提交回复
热议问题