Conversation

@wagi Heh, that's because only echo stderr is redirected to /dev/null, but the error message is from zsh itself as it tries to redirect stdout. This would work:

$SHELL -c 'echo "foo" > file' 2> /dev/null

1
0
0

@wagi This also works:

(echo "foo" > file) 2>/dev/null
{echo "foo" > file} 2>/dev/null

1
0
0
@ptesarik @wagi ^this

You have to use brackets for builtins like "echo".
1
0
1

@monsieuricon @wagi Not sure what you mean. FWIW both of the above lines produce no output with zsh-5.9.

1
0
0
@ptesarik @wagi I was merely confirming that your answer is the correct one. :)
1
0
2

@monsieuricon @wagi But I think it does not matter whether "echo" is a shell builtin. You would run into the same issue if the redirection fails for an external command.

1
0
1
@ptesarik @wagi Oh, you're right! Sorry, I was for some reason focused on echo being a builtin.
1
0
1
@monsieuricon @ptesarik @wagi tbh I had the same wrong assumption
0
0
0