[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: |
Mon, 12 Feb 2024 00:07:06 +0100 |
User-agent: |
Evolution 3.50.3-1 |
On Sun, 2024-02-11 at 09:16 -0500, Greg Wooledge wrote:
> I'm not sure what "/proc/self" actually is.
I think it always points to the PID of whoever open it.
https://github.com/torvalds/linux/blob/841c35169323cd833294798e58b9bf63fa4fa1de/Documentation/filesystems/proc.rst#L127-L128
>
> unicorn:~$ ls -l /proc/self
> lrwxrwxrwx 1 root root 0 Feb 10 04:12 /proc/self -> 20906/
> unicorn:~$ ls -l /proc/self
> lrwxrwxrwx 1 root root 0 Feb 10 04:12 /proc/self -> 20907/
>
> In this case, it seems to be using the PID of "ls" rather than the
> PID
> of the shell.
Yes, because it's ls which gets /proc/self as a plain argument and ls
which does any resolvin.
> If you wanted the shell's environment variables, you'd be better off
> using $$ instead:
Sure, but see my other reply from just a few minutes ago... for my
actual use case that's not what I want (i.e. I want the PID of the
process).
My finding about the differing behaviour when redirecting a /proc/self
file were just an accident and won't be a problem for my actual use.
> Bash forks a subshell to run tr with the redirection being performed
> inside the subshell.
Fair enough, and that - I guess - is what will happen when I do it as
part of a pipe.
But then I don't understand why comm has the name of the process
(shouldn't it be at worst something like bash-subshell or so ^^?) and
even less why the environment seems empty (shouldn't it be the same
than the shell's?).
Thanks,
Chris.
- Re: why does </proc/self/environ not work in bash?, (continued)
- Re: why does </proc/self/environ not work in bash?, Chet Ramey, 2024/02/12
- Re: why does </proc/self/environ not work in bash?, Christoph Anton Mitterer, 2024/02/12
- Re: why does </proc/self/environ not work in bash?, Lawrence Velázquez, 2024/02/12
- Re: why does </proc/self/environ not work in bash?, Chet Ramey, 2024/02/13
- Re: why does </proc/self/environ not work in bash?, Chet Ramey, 2024/02/13
- Re: why does </proc/self/environ not work in bash?, Kerin Millar, 2024/02/11
- Re: why does </proc/self/environ not work in bash?, Christoph Anton Mitterer, 2024/02/11
Re: why does </proc/self/environ not work in bash?, Greg Wooledge, 2024/02/11
Re: why does </proc/self/environ not work in bash?, Chet Ramey, 2024/02/12
- Re: why does </proc/self/environ not work in bash?, Zachary Santer, 2024/02/12
- Re: why does </proc/self/environ not work in bash?, Chet Ramey, 2024/02/12
- Re: why does </proc/self/environ not work in bash?, Zachary Santer, 2024/02/12
- Re: why does </proc/self/environ not work in bash?, Chet Ramey, 2024/02/13
- Re: why does </proc/self/environ not work in bash?, Zachary Santer, 2024/02/13
- Re: why does </proc/self/environ not work in bash?, Chet Ramey, 2024/02/13
- Re: why does </proc/self/environ not work in bash?, Zachary Santer, 2024/02/13
- Re: why does </proc/self/environ not work in bash?, Chet Ramey, 2024/02/13
- Re: why does </proc/self/environ not work in bash?, Zachary Santer, 2024/02/14