Writing own Unix shell in C - Problems with PATH and execv
Posted
by
user1287523
on Stack Overflow
See other posts from Stack Overflow
or by user1287523
Published on 2012-09-29T05:03:36Z
Indexed on
2012/09/29
9:37 UTC
Read the original article
Hit count: 149
I'm writing my own shell in C. It needs to be able to display the users current directory, execute commands based on the full path (must use execv), and allow the user to change the directory with cd.
This IS homework. The teacher only gave us a basic primer on C and a very brief skeleton on how the program should work. Since I'm not one to give up easily I've been researching how to do this for three days, but now I'm stumped.
This is what I have so far:
- Displays the user's username, computername, and current directory (defaults to home directory).
- Prompts the user for input, and gets the input
- Splits the user's input by " " into an array of arguments
- Splits the environment variable PATH by ":" into an array of tokens
I'm not sure how to proceed from here. I know I've got to use the execv command but in my research on google I haven't really found an example I understand. For instance, if the command is bin/ls, how does execv know the display all files/folders from the home directory? How do I tell the system I changed the directory?
I've been using this site a lot which has been helpful: http://linuxgazette.net/111/ramankutty.html but again, I'm stumped.
Thanks for your help. Let me know if I should post some of my existing code, I'm wasn't sure if it was necessary though.
© Stack Overflow or respective owner