2018-04-28 00:23:51 +0200, Martijn Dekker: [...] > That said, do you have any opinion on whether something like > { ... ; } 3>&- > should push/restore a closed file descriptor if it's already closed, so that > the effect of exec-ing that descriptor within the compound command is local > to that compound command? [...]
Actually, in my list of "issues" I plan to some day raise to the Austin Group, I had: sh -c '{ exec > a; } > b; echo x' > c which sounds like it's the same. Do we honour the compound command asking for stdout to be redirected, or do we honour the "> b" redirection being temporary and apply only to the command substitution? I'm undecided here, though I'd tend to lean the same way as you do. The problem can also be expressed as: redir_stdout() { exec > "$1" } redir_stdout file1 > file2 Or: close() { eval "exec $1>&-"; } close 1 > file f() { close 1 redir_stdout file echo foo close 1 } f > /dev/null POSIX could arbitrate based on the number of implementations that go one or the other way. Or leave it unspecified (I've not checked what it currently says).. -- Stephane