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: Greg Wooledge
Subject: Re: why does </proc/self/environ not work in bash?
Date: Sun, 11 Feb 2024 10:39:52 -0500

On Mon, Feb 12, 2024 at 12:12:33AM +0900, Koichi Murase wrote:
> 2024年2月11日(日) 23:17 Greg Wooledge <greg@wooledge.org>:
> > But... wait, now I'm even more confused:
> >
> > unicorn:~$ ( sleep 3 & exec 3</proc/$!/environ ; cat <&3 )
> > unicorn:~$
> >
> > How come *that* one didn't print anything?
> 
> I think the stream opened for /proc/xxx/environ is invalidated on exec
> of the process of PID xxx.

unicorn:~$ ( sleep 3 & cat /proc/$!/environ )
SHELL=/bin/bashWINDOWID=8388618QT[...]

unicorn:~$ ( sleep 3 & cat < /proc/$!/environ )
SHELL=/bin/bashWINDOWID=8388618QT[...]

unicorn:~$ ( sleep 3 & read -d '' < /proc/$!/environ ; printf %s\\n "$REPLY" )
SHELL=/bin/bash

unicorn:~$ ( sleep 3 & exec < /proc/$!/environ ; cat )
unicorn:~$ 

unicorn:~$ ( sleep 3 & exec < /proc/$!/environ ; read -d ''; printf %s\\n 
"$REPLY" )
SHELL=/bin/bash

I still don't understand what's happening here, but I'm pretty much
convinced it's happening at the kernel level, not the shell level.

unicorn:~$ uname -a
Linux unicorn 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 
(2024-02-01) x86_64 GNU/Linux



reply via email to

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