[Techtalk] environ variable in C

David Sumbler david at aeolia.co.uk
Fri Apr 2 11:45:33 EST 2004


I'm carrying on with my attempts to learn C.

I've just been experimenting with a little program to print out the
contents of the "environ" variable.

For some reason it doesn't print all of my bash environment variables
- it prints rather less than half of them.

Is this normal?  All of the variables mentioned by name in the environ
man page, and which are set in my bash shell, are listed, except for
COLUMNS.  Some of the other items not found, and which I should have
thought might be useful in a C program, are EUID, UID, GROUPS and
LINES.

BTW, I'm sure there's nothing wrong with the program, which is
straight out of Beginning Linux Programming:

#include <stdlib.h>
#include <stdio.h>

extern char **environ;

int main()
{
    char **env = environ;

    while(*env) {
        printf("%s\n",*env);
        env++;
    }
    exit(0);
}

David

-- 


More information about the Techtalk mailing list