ceving
ceving

Reputation: 23824

How to redirect in a process substitution?

I tried to redirect standard error to a file having restricted permissions. This is what I did:

exec 2> >(umask 077; exec > stderr.log)

The idea was to redirect standard error to a process, change the umask and redirect once more to the log file.

But it does not work. The command stalls and terminates with 141 after pressing return.

The Bash manual does not define "process list" in the manual.

Can anybody explain the failure?

Upvotes: 2

Views: 635

Answers (1)

anubhava
anubhava

Reputation: 785128

You should use cat inside sub-process to write the data coming in stdin of the process inside (...) which is actually stderr of parent process:

exec 2> >(umask 077; cat > stderr.log)

Process substitution feeds the output of a process (or processes) into the stdin of another process. Just by doing exec > stderr.log you're merely redirecting stdout of sub-process to a file however you're not actually writing anything to stdout inside >(...)

Upvotes: 3

Related Questions