help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why does </proc/self/environ not work in bash?


From: Christoph Anton Mitterer
Subject: Re: why does </proc/self/environ not work in bash?
Date: Sun, 11 Feb 2024 23:44:26 +0100
User-agent: Evolution 3.50.3-1

On Sun, 2024-02-11 at 13:16 +0900, Koichi Murase wrote:
> I haven't checked how Bash actually implements it in the codebase,
> but
> redirections can be performed in different places depending on the
> implementation. One could open the file in the parent process and
> perform fork&exec as a possible implementation, but as another
> implementation, one can first perform the fork, perform the
> redirection, and finally perform the exec. In that case, /proc/self
> would reference cat or tr even when it is opened by a redirection.

Well, even if technically it may make sense to do it in the forked
process, I would have interpreted POSIX as this is to be done in the
shell:

"2.9.1 Simple Commands" says something like:
> 3.  Redirections shall be performed as described in Redirection.

And since a command name results in our case, there's not even the
thing with step 3. and 4. being swappable (though even if, that would
IMO not change that the shell is to open the redirection).

And only after the 4 initial steps it says:
> If there is a command name, execution shall continue as described
> in Command Search and Execution.

So I'd have read this at, by that point, all redirections have to be
already performed, and if so, they need be performed in the context of
the shell.


OTOH, POSIX is big and there may be any other place in it which I don't
know/remember which says contrary ;-)
And one can at least assume, that POSIX wasn't written with magic files
like those in /proc/ in mind.


But even with the explanation of yours, I don't understand how the
environ can be empty.
Shouldn't that be there and inherited, even if it
forks,redirects,execs?

Cheers,
Chris.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]