微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在bash脚本中静默输出?

我有一个程序,输出到stdout,并希望在bash脚本中静输出,同时管道到文件

例如,运行程序将输出

% myprogram
% WELCOME TO MY PROGRAM
% Done.

我想让以下脚本不向命令行输出任何内容

#!/bin/bash
myprogram > sample.s
如果它输出到stderr,你会想要沉。你可以通过重定向文件描述符2:
# Send stdout to sample.s,stderr to sample.err
myprogram > sample.s 2> sample.err

# Send both stdout and stderr to sample.s
myprogram &> sample.s      # New bash Syntax
myprogram > sample.s 2>&1  # Older sh Syntax

# Log output,hide errors.
myprogram > sample.s 2> /dev/null

原文地址:https://www.jb51.cc/bash/392442.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐