Home > OS >  How to pass stderr to a command stream, then back to the terminal?
How to pass stderr to a command stream, then back to the terminal?

Time:12-21

I'm using bash, but perhaps most shells behave similarly in this regard. If not, then my question pertains to bash.

There's a regularly used command that always issues a spurious error message (to stderr), but MAY sometimes issue error messages that are important. I figured I could pipe stderr to grep, then use -v option to filter the offending line that's otherwise noise. Whatever passes through the filter on stderr should go right back to the original destination (presumably the user's terminal). How do I do this?

(Getting the source and editing it to make a custom version that doesn't spit out that error is obviously possible but out of the question for practical reasons.)

CodePudding user response:

Output grep output to stderr.

thecommand 2> >(grep -v 'something' >&2)
  • Related