4

If I have noclobber set in my interactive shell (set -o noclobber), I noticed process substitution doesn't work:

# echo hello > >(cat) -bash: /dev/fd/62: cannot overwrite existing file 

If I turn off noclobber permanently (set +o noclobber) it works fine:

# echo hello > >(cat) hello 

I tried overriding noclobber with >| like this:

echo hello > >|(cat) -bash: syntax error near unexpected token `>|' 

Is there a way to disable noclobber temporarily?

UPDATE: actually, it seems unreasonable for noclobber to take effect when the output goes to process substitution, because there is no file that would be "clobbered". It seems like it would be a good and safe to always use the >| and 2>| overrides to noclobber to prevent "cannot overwrite existing file" errors in case noclobber is inadvertently turned on.

1
  • This may seem obvious, but I was confused by it today and couldn't find a solution online, so I'm creating this question and answer for anyone who might have tripped into the same hole. Commented Nov 29, 2019 at 20:09

1 Answer 1

3

Override noclobber in the same way done for files using >|:

# echo hello >| >(cat) hello 

The >| must be with the redirection symbol (>), not as part of the process substitution (>(…)).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.