如何在沉默一个bash脚本的输出? [英] How to silence output in a bash script?
本文介绍了如何在沉默一个bash脚本的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个程序,输出到标准输出,并想沉默,石油产量在bash脚本,而管道到一个文件中。
例如,运行程序将输出:
%myprogram
%欢迎我的计划
%完成。
我想下面的脚本不输出任何命令行:
#!/斌/庆典
myprogram> sample.s
解决方案
如果它输出到标准错误以及你要沉默了。您可以通过重新做文件描述符2:
#发送到标准输出sample.s,错误输出到sample.err
myprogram> sample.s 2 - ; sample.err#发送标准输出和标准错误到sample.s
myprogram&安培;> sample.s#新的bash语法
myprogram> sample.s 2 - ;&放大器; 1#较早的sh语法#日志输出,隐藏的错误。
myprogram> sample.s 2 - ;的/ dev / null的
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:
% myprogram
% WELCOME TO MY PROGRAM
% Done.
I want the following script to not output anything to the command-line:
#!/bin/bash
myprogram > sample.s
解决方案
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 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
这篇关于如何在沉默一个bash脚本的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文