NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Silly shell question
On Mar 22, 2016, at 4:39 PM, Swift Griggs wrote:
In ksh, when you use the 'export' keyword, what is actually going
on? Does it create a copy of the variable in memory? I doubt it
since I tried a test and I could see the exported version changing
even if I just change the original variable:
# FOO=abc
# export FOO
# ksh
[...]
Try printenv before and after. Man printenv and environ, and getenv.
Basically, exported variables become part an array of character
strings in
the memory space of child process (as a copy). In a way, it's similar to
to command line arguments. It's actually part of C , not just unix.
In C you can optionally pass a 3rd parameter to main
--
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char * argv[] , char **environ)
{
printf("main %p\n", main);
printf("argv %p\n", argv);
printf("environ %p\n", environ);
printf("malloc'ed byte %p\n",malloc(1));
}
Compile with symbols, and launch gdb, set a break point and
you can poke around. (print environ[4], print strlen(environ[4]), etc ).
Sorry if this seems like a dumb question. I'm just curious about
the intrinsics of how
it works. I looked at the source code for ast-ksh, but it's pretty
huge and hard to
Might want to look at the source for something simpler, like
printenv, and env.
/usr/src/usr.bin/env/env.c
/usr/src/usr.bin/printenv/printenv.c
Home |
Main Index |
Thread Index |
Old Index