Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
The first while loop does not give proper results.
But when I changed the declaration of global variable to "extern char ** environ"it gave proper results.
can some one clarify me this as why is this happening. As per my understanding char* environ and char** environ are same. And also the second loop worked fine though I declared envp as char * envp.
2.) When I ran the above program with out passing any command line arguments, it still worked and gave proper results with loop 2, the envp argument. How come? I didnt pass this argument, how could it still pull in the environment variables to envp? And the main thing, if I would like to pass the command line arguments I would I do that?
Thanks a lot in advance.
Last edited by vtn; 08-16-2009 at 08:10 AM.
Reason: corrected the code posted as it diverts the problem
1. This part is tricky. IMO when you add extern char* environ you redefine it, in fact. On the other hand, if you use exactly the same extern as in unistd.h, it is just a repeat. In fact, I wouldn't redefine environ (any way), just compile with -D_GNU_SOURCE (if you do not have other reasons to leave it off).
Thanks for your response and I understood what I was doing regarding first loop..thanks.
Regarding the second loop, my question was different...when I ran the code I was running one loop at a time and when I posted it I forgot to initialize i to 0... my bad . Anyways I edited the code I posted. But my question was, after compiling the code and if I run it with out passing the command line arguments like ./a.out at the prompt, envp is still available inside the code. I was assuming it to complain that envp unkown variable when I run it with out passing the arguments.
Also if I need to pass command line arguments when running a program, how would I do it?