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.
- 10-11-2011 #1Just 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!
- 10-11-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,142
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!
- 10-11-2011 #3Just Joined!
- Join Date
- Oct 2011
- Posts
- 2
could you give me an example?
- 10-11-2011 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,142
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 PATHSometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
