Writing a Unix Shell - Part II - Why ?
Hello all. I was reading the blog on writing a UNIX shell as seen here. The author of the article states the following:
"If you try to execute the cd command, you will get an error that says: cd: No such file or directory" AND "The current working directory of the parent has not changed, since the command was executed in the child." Here is the code for the above comments made by the author. So my question is why does the command not work when executed in the child process ? Code:
#include <stdlib.h> |
The answer is located in the linked article one line below the quoted part:
Quote:
|
Quote:
|
Very simple if you think of where you are...... Because the child shell does not contain that built-in command whereas the parent does contain it.
IIF the child is a clone of the parent then it contains the same commands. If it is not a clone then it only contains the commands the programmer chose to include. Wrap your head around this. Program A is the parent shell. Program B is the child shell (probably written my a different programmer). What is included in A may not be (and likely is not -- at least in the same form) included in B. Really simple to see from the outside. Program A launches program B then is gone and only what was included in B is now available. The same applies to any separate program launched by the shell. Only what is intrinsic to the currently running program is available without external system calls. |
Quote:
|
All times are GMT -5. The time now is 12:07 PM. |