Problem with getenv()

From: Roby (nada_at_nada.net)
Date: 03/31/04


Date: Wed, 31 Mar 2004 15:25:20 GMT

Why are some of my environment variables ignored by getenv?
For example, entering set in a bash shell shows me a list which includes

OSTYPE=linux-gnu
SHLVL=2

getenv finds "SHLVL" but not "OSTYPE"

Code:
// evar.c
#include <stdlib.h>

int main( int argc, char **argv )
{
char *P;

if( argc != 2 )
    {
    puts( "Syntax: evar <e-var name>" );
    puts( " Displays the value assigned to e-var" );
    return( 1 );
    }

if( ( P = getenv( argv[ 1 ] ) ) == NULL )
    P = "( not found )";

printf( "%s = %s\n", argv[ 1 ], P );
return( 0 );
} /* main */

Thanks!



Relevant Pages

  • Re: Maintaining multivariable state (newbie question)
    ... extended with various options, and I've ended up making each function taking (..., int argc, char *argv) and then each function would parse it. ... argc, char *argv), but for some reason I needed to change some of the things temporarily, and restore them, so I've ended up doing something like a stack for each global variable. ... And when I started reading lisp I understand the wisdom behind special variables, and all my wasted hours behind emulating what's already have been done. ... That plus the multiple-value returns (Another invention that I needed these days in a C++ code to overcome total rewrite of foreign code portions in a much larger tool - mainly to avoid massive amounts of DLL's to be recompiled). ...
    (comp.lang.lisp)
  • Re: The contents of the file is not read..
    ... int main(int argc, char *argv) ... Buffer overflow protection. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Newbee needs once more again help with passing arrays out of a function
    ... int argc, char *argv) ... it's best to copy and paste a compilable program ... give them the starting address of some region in memory. ...
    (comp.lang.c)
  • [PATCH -tip 7/9] perf probe: Add argv_split() from lib/argv_split.c
    ... int argc, i, need_dwarf = 0; ... * Helper function for splitting a string into an argv-like array. ... char *strxfrchar; ...
    (Linux-Kernel)
  • Re: function
    ... main (int argc, char *argv) ... exit; ... Why the termination string character? ...
    (comp.lang.c)