separte pipe for stderr and stout in a bash script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
separte pipe for stderr and stout in a bash script
hi all
what's the best way to output the stderr and stdout of a shell command thru different pipes?
I want to process the stderr different from stout, generated by a command. How to combine both and still have the same output descriptors? In other words, how
to combine ("a one liner"!) the two commands:
what's the best way to output the stderr and stdout of a shell command thru different pipes?
I want to process the stderr different from stout, generated by a command. How to combine both and still have the same output descriptors? In other words, how
to combine ("a one liner"!) the two commands:
thats what i did too however i was wondering wether there is a "smart" way to do it with e.g. the 'exec' command somehow. The sample below is now my final:
I am sorry for necroing this thread, but I found it while searching for a very similar problem and in case someone else finds this after me I want to provide an even better answer.
First,
Code:
( cmd | sed 's|out|OUT|g' ) 3>&1 1>&2 2>&3 | sed 's|err|ERR|g'
is really all you need, the swapping at the end is superfluous, because nothing is done with it after the second sed and the descriptors get reset to their previous state automatically.
As a little extra *g*, you can use this to play all files found under the current directory with mplayer without losing control (because /dev/stdin doesn't get redirected from /dev/null) and without using a pipe made by mkfifo:
Code:
(xargs -a /proc/self/fd/3 -0 mplayer -vo null -shuffle) 3< <(find -type f -print0)
my source: h++p://stupefydeveloper.blogspot.de/2008/10/bash-file-descriptors_20.html
I hope this necro was not too annoying and instead relevant and "timely" enough
Reopening an old thread is usually ok as long as you're adding something new and useful to the original conversation, and particularly if you also make it clear that you are re-opening it. You've done both, so I say good work.
I just want to point out clearly that what you've posted uses the bash-specific process substitution, and is therefore not portable across shells, unlike the standardized redirections and fifos. But they are very convenient.
As the above link points out, ksh appears to also have process substitution built in, but apparently it can't be combined with shell redirections in the way shown above. Perhaps with dedicated file descriptors?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.