如何在bash脚本中静默输出?
发布时间:2020-12-15 16:49:22 所属栏目:安全 来源:网络整理
导读:我有一个程序,输出到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 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |