I am rewriting the problem since it's not clearly understood as far as I see. I implement my own shell in C which needs to support all commands the original one does.
The problem is to execute all existing UNIX bash commands in C without using execvp()
or system()
functions which already let you do that easily.
To do that, I need to search all required directories which may consist any kind of UNIX commands. I just want to know that:
Do I really be sure that I support all possible UNIX commands in any distribution when I checked all directories in my PATH
environment variable? (which becomes /bin/
, /usr/bin/
, /usr/local/bin
in my machine)
I have also found a method which gets the full directory of a file you inserted called realpath() . But unfortunately, it returns (null)
when I attempt to get the directory of the command inserted in my own shell.
What else do you suggest me to achieve this problem? As a last solution, does it make sense to search whole computer recursively from the root to find the command inserted?
If there's something unclear, please let me know to clarify. I would be very thankful if you could answer with a piece of example code and clear [on hold] tag in the question if you think it's clearly described from now.
Thanks in advance!