Jordan Mackie
Jordan Mackie

Reputation: 2406

Redirect sterr in subshell to stdout in current shell in bash script

I have a subshell carrying out a function:

local thing=$( doFunc )

doFunc sends logging output to stderr (2) and 'thing' gets assigned to doFunc's output on stdout (1).

How can I run this line, but print stderr from the subshell to stdout in the current shell?

Upvotes: 3

Views: 1477

Answers (1)

Eric Renouf
Eric Renouf

Reputation: 14500

You can first make a copy of stdout on another FD, then redirect to that like

exec 3>&1
local thing=$(doFunc 2>&3)

Upvotes: 10

Related Questions