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.
