如何在Bash脚本中静音输出?
发布时间:2020-12-16 01:40:23 所属栏目:安全 来源:网络整理
导读:我有一个程序输出到stdout,并希望在管道到文件时在 Bash脚本中静音该输出. 例如,运行程序将输出: % myprogram% WELCOME TO MY PROGRAM% Done. 我希望以下脚本不向终端输出任何内容: #!/bin/bashmyprogram sample.s 解决方法 如果它输出到stderr你也会想要
我有一个程序输出到stdout,并希望在管道到文件时在
Bash脚本中静音该输出.
例如,运行程序将输出: % myprogram % WELCOME TO MY PROGRAM % Done. 我希望以下脚本不向终端输出任何内容: #!/bin/bash myprogram > sample.s 解决方法
如果它输出到stderr你也会想要沉默.你可以通过重定向文件描述符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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |