我有一个程序,输出到stdout,并希望在bash脚本中静默该输出,同时管道到文件。
例如,运行程序将输出:
% myprogram % WELCOME TO MY PROGRAM % Done.
#!/bin/bash myprogram > sample.s
如果它输出到stderr,你会想要沉默。你可以通过重定向文件描述符2:
原文链接:https://www.f2er.com/bash/392442.html# 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