On 11/01/2025 00:50, Christoph Anton Mitterer via austin-group-l at The
Open Group wrote:
Not sure what’s the intention of not passing on FDs > 2, because one
could always just close such FDs via redirection specifically for the
utility.
Likewise, when any FD > 2 needs to be passed to an external utility, one
could always just duplicate such FDs via redirection specifically for
the utility.
$ mksh -c "exec 8</dev/null; ls /proc/self/fd/8"
ls: cannot access '/proc/self/fd/8': No such file or directory
$ mksh -c "exec 8</dev/null; ls /proc/self/fd/8 8<&8"
/proc/self/fd/8
$ ksh -c "exec 8</dev/null; ls /proc/self/fd/8"
ls: cannot access '/proc/self/fd/8': No such file or directory
$ ksh -c "exec 8</dev/null; ls /proc/self/fd/8 8<&8"
/proc/self/fd/8
Any other means to get the desired goal (in a portable way)?
As Lawrence Velázquez rightly replied, your example should already work
in all shells. For other examples where the utilities need to access
those FDs themselves, the above should be enough to make all shells work
the same way.
Cheers,
Harald van Dijk