Funding Chain
Funding Chain

Reputation: 1

How to print out error messages into terminal screen while doing pipes (linux bash)

In linux bash terminal, the command I want to run is of the form: cmd | cmd2 > somefile.txt.

However, I also want error message in cmd to be shown in terminal screen. So this is different from redirecting stderr to stdout. What is the way to do this?

Upvotes: 0

Views: 1192

Answers (1)

Varun
Varun

Reputation: 691

Error messages written to standard error will not be sent to the piped command. I mean if your command is:

cmd | cmd2

then only the stdout messages from cmd will be piped to cmd2 and not stderr messages.

Here is an example I used. I tried cating a non-existing file and tried greping some text:

$ cat non-existing-file.txt | grep something > grepped-text.txt
cat: non-existing-file.txt: No such file or directory

Upvotes: 2

Related Questions