Re: Redirecting error message from ${parameter:?word}
From:
Greg Wooledge
Subject:
Re: Redirecting error message from ${parameter:?word}
Date:
Tue, 14 Jan 2020 13:27:41 -0500
User-agent:
Mutt/1.10.1 (2018-07-13)
On Tue, Jan 14, 2020 at 07:17:34PM +0100, Michael Siegel wrote:
> Am 12.01.20 um 07:37 schrieb Eli Schwartz:
> >
> > It should suffice to use any compound command; the simplest would be to
> > use { cmd; } 2>/dev/null
> >
> > No subshell needed, which it seems is something the OP cared about.
>
> Exactly, that's what I was looking for.
>
> But why does this work? I mean, I get why redirecting the shell's error
> stream works when using a subshell. But how does using a compound
> command lead to masking the expansion error?
Same reason that { time foo ...; } 2>file works.
The brace grouping introduces a new redirection context point. It's
not a whole process, but there's enough *state* involved that you
can have separate file redirections inside vs. outside.
https://mywiki.wooledge.org/BashFAQ/032