Thread: How to check and change environment variables in C

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    13

    How to check and change environment variables in C

    Hi,

    I want to know how can I change and check environment variables in a C program. For instance I want to check $HOME or $PATH an change them

    Thanks in advance

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    getenv() and setenv()

    check your man pages for these functions.

  3. #3
    .
    Join Date
    Nov 2003
    Posts
    307
    It's putenv().

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by jim mcnamara
    It's putenv().
    setenv() gives you more control, check your man pages

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    But neither of them change the parent environment.

    If you program does putenv("PATH=foo");
    Then running the program does NOT change the PATH in your shell.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    .
    Join Date
    Nov 2003
    Posts
    307
    Because you are running in a child process.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    13
    Thanks guys. Linux rules

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  4. A breakthrough
    By loopy in forum Linux Programming
    Replies: 4
    Last Post: 11-26-2003, 06:46 PM
  5. writing/reading from file produces double results.
    By stumon in forum C Programming
    Replies: 4
    Last Post: 03-20-2003, 04:01 PM