Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Do file descriptors survive to subshell?



OK, thanks. I was planning to use read -t -u on a descriptor obtained
by exported variable SOMETHING_ID, to differentiate between `exec
zsh-5.2-dev-1` and `zsh-5.2-dev-1`. If it would fail then it's
non-exec, regular start. Now I see that SHLVL should be used to
differentiate that?

BTW., read -t -u seems to succeed as many times as there are lines in
a file (file descriptor), that's rather unexpected, it rather should
do some "read char, put char back" thing, or something not changing FD
position in file I would say

Best regards,
Sebastian Gniazdowski


On 12 September 2016 at 18:19, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> It depends how the FD was opened.
>
>> But the "survive FD" feature should work only for
>> "exec zsh-5.2-dev-1", not "zsh-5.2-dev-1", shouldn't it ...
>
> well, if you ran
>
>   zsh-5.2-dev-1 3< myfile
>
> you'd be a bit annoyed if FD 3 was closed, wouldn't you?
> And of course 0, 1 and 2 are left open.
>
> So for FDs opened by / known to the user, it's expected that they'll
> survive; internal FDs used by the shell should be closed.  One example
> of an FD the shell uses internally is for terminal management --- we
> don't do this directly on the user-visible FDs for reasons I don't
> think I ever fully understood.  Because this is opened early, it's
> usualy FD 10, i.e. just outside the easily accessible range (that
> traditionally shells keep away from allowing you to manipulate
> directly) 0 to 9.
>
> pws



Messages sorted by: Reverse Date, Date, Thread, Author