On Sun, 2025-01-12 at 17:58 -0500, Lawrence Velázquez via austin-group-
l at The Open Group wrote:
> > Which means that the above redirection (</does-not-exist/file)
> > should
> > actually be guaranteed to work portably,
> > but doing something more complex like:
> >    command exec 3>&1 || return 125
> >    captured_stderr="$( command exec 2>&1 >&3 3>&- || exit 125;
> > utility 
> > )"  ||  exit_status="$?"
> >    command exec 3>&- || return 125
> > 
> > is not guaranteed to work.
> 
> Not in general, but for this specific example I don't see why not.
> It's portable to use FD 3 inside the command substitution because
> subshells aren't utilities, and the actual "utility" clearly doesn't
> try to use FD 3, given that you close it first.

Well that was just one example, perhaps not the best for the point I
was trying to make :-)
It could easily be that the utility does in fact use some > 2 FD.

> And behold, it works with the four FD-closing shells yet mentioned:

Is it - with the particular example - guaranteed *by POSIX*, that the 
>&3 still works for the utility? I guess so, but not really an expert.

Cheers,
Chris.

    • Re: exe... Chet Ramey via austin-group-l at The Open Group
      • Re:... Martijn Dekker via austin-group-l at The Open Group
        • ... Christoph Anton Mitterer via austin-group-l at The Open Group
          • ... Lawrence Velázquez via austin-group-l at The Open Group
  • Re: exec red... Lawrence Velázquez via austin-group-l at The Open Group
    • Re: exe... Geoff Clare via austin-group-l at The Open Group
      • Re:... Lawrence Velázquez via austin-group-l at The Open Group
        • ... Geoff Clare via austin-group-l at The Open Group
      • Re:... Christoph Anton Mitterer via austin-group-l at The Open Group
        • ... Geoff Clare via austin-group-l at The Open Group
    • Re: exe... Christoph Anton Mitterer via austin-group-l at The Open Group
  • Re: exec red... Harald van Dijk via austin-group-l at The Open Group
    • Re: exe... Christoph Anton Mitterer via austin-group-l at The Open Group
      • Re:... Oğuz via austin-group-l at The Open Group
    • Re: exe... Christoph Anton Mitterer via austin-group-l at The Open Group
      • Re:... Geoff Clare via austin-group-l at The Open Group
        • ... Geoff Clare via austin-group-l at The Open Group
        • ... Steffen Nurpmeso via austin-group-l at The Open Group
          • ... Steffen Nurpmeso via austin-group-l at The Open Group
        • ... Christoph Anton Mitterer via austin-group-l at The Open Group
          • ... Geoff Clare via austin-group-l at The Open Group

Reply via email to