Discussion:
[9fans] environment variables bevanving weird
(too old to reply)
Friedrich Psiorz
2012-06-08 23:02:21 UTC
Permalink
hi! I'm new to Plan 9 and I don't understand this behavior:

I wrote a program that basically just does
putenv("foo", "bar");

After running it,
echo $foo
prints just an empty line, while
cat /env/foo
prints bar. Can anyone explain?
Federico Benavento
2012-06-08 23:13:53 UTC
Permalink
see env(3), basically the rfork flags affect it. check the man page.
Post by Friedrich Psiorz
I wrote a program that basically just does
putenv("foo", "bar");
After running it,
echo $foo
prints just an empty line, while
cat /env/foo
prints bar. Can anyone explain?
---
Federico Benavento
***@gmail.com
vrtra
2012-06-08 23:13:05 UTC
Permalink
Post by Friedrich Psiorz
I wrote a program that basically just does
putenv("foo", "bar");
After running it,
echo $foo
prints just an empty line, while
cat /env/foo
prints bar. Can anyone explain?
I asked a somewhat same question a month back
http://9fans.net/archive/2012/05/281

The reason seems to be that while creating a variable foo
in rc is immediately reflected to /env/foo, the reverse is
not true. That is, creating a new file under /env/baz does
not update the current rc instance with a new variable $baz

So in this case, putenv is actually writing to /env/foo,
and it would be visible only if you start a new rc
instance. (or just read from the same file.)

v

Loading...