Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I'm brand new to linux. I am trying to create a shell using C coding and compiling it on Linux. I looked up on the internet how to check ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    2

    Checking and Modifying PATH of a shell in linux using C coding.


    Hi, I'm brand new to linux. I am trying to create a shell using C coding and compiling it on Linux. I looked up on the internet how to check and modify paths via Linux commands on the command prompt:
    echo $PATH //to view the paths
    PATH = $PATH:[directory] //to add a directory to the path

    To my understanding, the path is just a bunch of directories that the program will look into when a program is executed.

    How am I to check/modify the PATH using the C programming language?

    I'm trying to use an 'execv' function which would run a new program given the path passed in as a parameter.

    How would I check the PATH from C? and how would I modify it in C such that when I compile the C code it gives me the shell?


    NOTE: This is my first time ever using Linux. I am trying to get my feet wet with it, so please bare with me.
    Thanks!

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,754
    The environment variables are context sensitive in that they only persist until the controlling program exits. So, if you change a PATH environment in a C program, its children will get the changes, but when the changing process is terminated, its parent knows nothing about the changes it made. As they say, you can't get there from here.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    2
    could you give me an example?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,754
    Example of what? Not being able to do what you want? Try it and you will see what I mean. To wit:

    shell->c-program (changes PATH) ->new program (sees new PATH)
    new program terminates -> c-program terminates -> shell does not see new PATH
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •